#include "DriverTiming.hpp"
#include <math.h>


DriverTiming::DriverTiming(const char *pRootPath, const char *pIniUIFilename, const char *pIniDriverMappingFilename, const char *pIniVehiculeClassMappingFilename)
{
	initialized = false;
	rootPath = pRootPath; 
	iniDriverMappingFilename = pIniDriverMappingFilename;
	iniVehiculeClassMappingFilename = pIniVehiculeClassMappingFilename;

	nbProfiles = GetPrivateProfileInt("Profiles", "count", 0, pIniUIFilename);
	for (int i = 0 ; i < nbProfiles; i++) {
		sprintf(tmp, "Profile.%d", (i+1));
		profiles[i].widgetOffsetX = (signed int)GetPrivateProfileInt(tmp, "DriverTiming.offsetX", 0, pIniUIFilename);
		profiles[i].widgetOffsetY = (signed int)GetPrivateProfileInt(tmp, "DriverTiming.offsetY", 0, pIniUIFilename);
		profiles[i].hide = GetPrivateProfileInt(tmp, "DriverTiming.hide", 0, pIniUIFilename) != 0;
	}

	//std::string str = rootPath;
	GetPrivateProfileString("UI Widgets", "DriverTiming.ini", "", tmp, 999, pIniUIFilename);
	//str.append(tmp);
	sprintf(iniUIFilename, "%s%s", rootPath, tmp);
	//iniUIFilename = str.c_str(); //pIniUIFilename; 
	available = GetPrivateProfileInt("Driver Timing", "available", 0, iniUIFilename) != 0;

	forceDisplay = false;
}

void DriverTiming::init(const ScreenInfoV01 &info, float ratio, float ratioWidth, float ratioHeight, Sprite spriteList[]) {
	if (!available) {
		initialized = true;
		return;
	}

	for (int i = 0 ; i < nbProfiles; i++) {
		profiles[i].widgetOffsetX *= ratioWidth;
		profiles[i].widgetOffsetY *= ratioHeight;
	}


	displayDurationUnpined = GetPrivateProfileInt("Driver Timing", "display.duration.unpined", 10, iniUIFilename);

	int posX = (int)(ratioWidth * GetPrivateProfileInt("Driver Timing", "image.left", 40, iniUIFilename));//40;
	int posY = (int)(ratioHeight * GetPrivateProfileInt("Driver Timing", "image.top", 550, iniUIFilename));//550;

	//LPDIRECT3DDEVICE9 dev = static_cast<LPDIRECT3DDEVICE9>(info.mDevice);	
	

	bgImageData.spriteIndex = GetPrivateProfileInt("Driver Timing", "image.id", 0, iniUIFilename) -1;
	if (bgImageData.spriteIndex > -1) {
		bgImageData.left = posX;
		bgImageData.top = posY;
		bgImageData.width = (int)(GetPrivateProfileInt("Driver Timing", "image.width", (int)spriteList[bgImageData.spriteIndex].width, iniUIFilename) * ratioWidth);
		bgImageData.height = (int)(GetPrivateProfileInt("Driver Timing", "image.height", (int)spriteList[bgImageData.spriteIndex].height, iniUIFilename) * ratioHeight);
		bgImageData.colorIndex = GetPrivateProfileInt("Driver Timing", "image.color.id", 1, iniUIFilename) -1;
	}
	////////////////////////////////////////////
	// S1
	////////////////////////////////////////////
	// S1 Tag
	s1TagAvailable = GetPrivateProfileInt("Driver Timing.S1.Tag", "available", 0, iniUIFilename) != 0;
	if (s1TagAvailable) {
		s1TagTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S1.Tag", "text.left", 0, iniUIFilename) * ratioWidth);
		s1TagTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S1.Tag", "text.top", 0, iniUIFilename) * ratioWidth);
		s1TagTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Timing.S1.Tag", "text.right", 100, iniUIFilename) * ratioWidth);
		s1TagTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Timing.S1.Tag", "text.bottom", 100, iniUIFilename) * ratioWidth);

		s1TagTextData.fontIndex = GetPrivateProfileInt("Driver Timing.S1.Tag", "text.font.id", 1, iniUIFilename) - 1;
		s1TagTextData.colorIndex = GetPrivateProfileInt("Driver Timing.S1.Tag", "text.font.color.id", 1, iniUIFilename) - 1;
		s1TagTextData.alignment = GetPrivateProfileInt("Driver Timing.S1.Tag", "text.alignment", 1, iniUIFilename);

		s1TagImageData.spriteIndex = GetPrivateProfileInt("Driver Timing.S1.Tag", "image.id", 0, iniUIFilename) -1;
		if (s1TagImageData.spriteIndex != -1) {
			s1TagImageData.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S1.Tag", "image.left", 0, iniUIFilename) * ratioWidth);
			s1TagImageData.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S1.Tag", "image.top", 0, iniUIFilename) * ratioHeight);
			s1TagImageData.width = (int)(GetPrivateProfileInt("Driver Timing.S1.Tag", "image.width", (int)spriteList[s1TagImageData.spriteIndex].width, iniUIFilename) * ratioWidth);
			s1TagImageData.height = (int)(GetPrivateProfileInt("Driver Timing.S1.Tag", "image.height", (int)spriteList[s1TagImageData.spriteIndex].height, iniUIFilename) * ratioHeight);
			s1TagImageData.colorIndex = GetPrivateProfileInt("Driver Timing.S1.Tag", "image.color.id", 1, iniUIFilename) -1;
		}
	}
	
	s1TagMyCatAvailable = GetPrivateProfileInt("Driver Timing.S1.Tag.IfBestInCat", "available", 0, iniUIFilename) != 0;
	if (s1TagMyCatAvailable) {
		s1TagMyCatTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S1.Tag.IfBestInCat", "text.left", -9999, iniUIFilename) * ratioWidth);
		s1TagMyCatTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S1.Tag.IfBestInCat", "text.top", -9999, iniUIFilename) * ratioWidth);
		s1TagMyCatTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Timing.S1.Tag.IfBestInCat", "text.right", -9999, iniUIFilename) * ratioWidth);
		s1TagMyCatTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Timing.S1.Tag.IfBestInCat", "text.bottom", -9999, iniUIFilename) * ratioWidth);
		if (s1TagMyCatTextData.rect.left < 0) s1TagMyCatTextData.rect.left = s1TagTextData.rect.left;
		if (s1TagMyCatTextData.rect.top < 0) s1TagMyCatTextData.rect.top = s1TagTextData.rect.top;
		if (s1TagMyCatTextData.rect.right < 0 ) s1TagMyCatTextData.rect.right = s1TagTextData.rect.right;
		if (s1TagMyCatTextData.rect.bottom < 0) s1TagMyCatTextData.rect.bottom = s1TagTextData.rect.bottom;

		s1TagMyCatTextData.fontIndex = GetPrivateProfileInt("Driver Timing.S1.Tag.IfBestInCat", "text.font.id", 1, iniUIFilename) - 1;
		s1TagMyCatTextData.colorIndex = GetPrivateProfileInt("Driver Timing.S1.Tag.IfBestInCat", "text.font.color.id", 1, iniUIFilename) - 1;
		s1TagMyCatTextData.alignment = GetPrivateProfileInt("Driver Timing.S1.Tag.IfBestInCat", "text.alignment", 1, iniUIFilename);

		s1TagMyCatImageData.spriteIndex = GetPrivateProfileInt("Driver Timing.S1.Tag.IfBestInCat", "image.id", 0, iniUIFilename) -1;
		if (s1TagMyCatImageData.spriteIndex != -1) {
			s1TagMyCatImageData.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S1.Tag.IfBestInCat", "image.left", 0, iniUIFilename) * ratioWidth);
			s1TagMyCatImageData.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S1.Tag.IfBestInCat", "image.top", 0, iniUIFilename) * ratioHeight);
			s1TagMyCatImageData.width = (int)(GetPrivateProfileInt("Driver Timing.S1.Tag.IfBestInCat", "image.width", (int)spriteList[s1TagMyCatImageData.spriteIndex].width, iniUIFilename) * ratioWidth);
			s1TagMyCatImageData.height = (int)(GetPrivateProfileInt("Driver Timing.S1.Tag.IfBestInCat", "image.height", (int)spriteList[s1TagMyCatImageData.spriteIndex].height, iniUIFilename) * ratioHeight);
			s1TagMyCatImageData.colorIndex = GetPrivateProfileInt("Driver Timing.S1.Tag.IfBestInCat", "image.color.id", 1, iniUIFilename) -1;
		}
	}

	s1TagAllCatAvailable = GetPrivateProfileInt("Driver Timing.S1.Tag.IfBestAllCat", "available", 0, iniUIFilename) != 0;
	if (s1TagAllCatAvailable) {
		s1TagAllCatTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S1.Tag.IfBestAllCat", "text.left", -9999, iniUIFilename) * ratioWidth);
		s1TagAllCatTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S1.Tag.IfBestAllCat", "text.top", -9999, iniUIFilename) * ratioWidth);
		s1TagAllCatTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Timing.S1.Tag.IfBestAllCat", "text.right", -9999, iniUIFilename) * ratioWidth);
		s1TagAllCatTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Timing.S1.Tag.IfBestAllCat", "text.bottom", -9999, iniUIFilename) * ratioWidth);
		if (s1TagAllCatTextData.rect.left < 0) s1TagAllCatTextData.rect.left = s1TagTextData.rect.left;
		if (s1TagAllCatTextData.rect.top < 0) s1TagAllCatTextData.rect.top = s1TagTextData.rect.top;
		if (s1TagAllCatTextData.rect.right < 0) s1TagAllCatTextData.rect.right = s1TagTextData.rect.right;
		if (s1TagAllCatTextData.rect.bottom < 0) s1TagAllCatTextData.rect.bottom = s1TagTextData.rect.bottom;

		s1TagAllCatTextData.fontIndex = GetPrivateProfileInt("Driver Timing.S1.Tag.IfBestAllCat", "text.font.id", 1, iniUIFilename) - 1;
		s1TagAllCatTextData.colorIndex = GetPrivateProfileInt("Driver Timing.S1.Tag.IfBestAllCat", "text.font.color.id", 1, iniUIFilename) - 1;
		s1TagAllCatTextData.alignment = GetPrivateProfileInt("Driver Timing.S1.Tag.IfBestAllCat", "text.alignment", 1, iniUIFilename);

		s1TagAllCatImageData.spriteIndex = GetPrivateProfileInt("Driver Timing.S1.Tag.IfBestAllCat", "image.id", 0, iniUIFilename) -1;
		if (s1TagAllCatImageData.spriteIndex != -1) {
			s1TagAllCatImageData.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S1.Tag.IfBestAllCat", "image.left", 0, iniUIFilename) * ratioWidth);
			s1TagAllCatImageData.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S1.Tag.IfBestAllCat", "image.top", 0, iniUIFilename) * ratioHeight);
			s1TagAllCatImageData.width = (int)(GetPrivateProfileInt("Driver Timing.S1.Tag.IfBestAllCat", "image.width", (int)spriteList[s1TagAllCatImageData.spriteIndex].width, iniUIFilename) * ratioWidth);
			s1TagAllCatImageData.height = (int)(GetPrivateProfileInt("Driver Timing.S1.Tag.IfBestAllCat", "image.height", (int)spriteList[s1TagAllCatImageData.spriteIndex].height, iniUIFilename) * ratioHeight);
			s1TagAllCatImageData.colorIndex = GetPrivateProfileInt("Driver Timing.S1.Tag.IfBestAllCat", "image.color.id", 1, iniUIFilename) -1;
		}
	}
	// S1 Value
	s1ValueAvailable = GetPrivateProfileInt("Driver Timing.S1.Value", "available", 0, iniUIFilename) != 0;
	if (s1ValueAvailable) {
		s1ValueTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S1.Value", "text.left", 0, iniUIFilename) * ratioWidth);
		s1ValueTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S1.Value", "text.top", 0, iniUIFilename) * ratioWidth);
		s1ValueTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Timing.S1.Value", "text.right", 100, iniUIFilename) * ratioWidth);
		s1ValueTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Timing.S1.Value", "text.bottom", 100, iniUIFilename) * ratioWidth);

		s1ValueTextData.fontIndex = GetPrivateProfileInt("Driver Timing.S1.Value", "text.font.id", 1, iniUIFilename) - 1;
		s1ValueTextData.colorIndex = GetPrivateProfileInt("Driver Timing.S1.Value", "text.font.color.id", 1, iniUIFilename) - 1;
		s1ValueTextData.alignment = GetPrivateProfileInt("Driver Timing.S1.Value", "text.alignment", 1, iniUIFilename);

		s1ValueImageData.spriteIndex = GetPrivateProfileInt("Driver Timing.S1.Value", "image.id", 0, iniUIFilename) -1;
		if (s1ValueImageData.spriteIndex != -1) {
			s1ValueImageData.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S1.Value", "image.left", 0, iniUIFilename) * ratioWidth);
			s1ValueImageData.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S1.Value", "image.top", 0, iniUIFilename) * ratioHeight);
			s1ValueImageData.width = (int)(GetPrivateProfileInt("Driver Timing.S1.Value", "image.width", (int)spriteList[s1ValueImageData.spriteIndex].width, iniUIFilename) * ratioWidth);
			s1ValueImageData.height = (int)(GetPrivateProfileInt("Driver Timing.S1.Value", "image.height", (int)spriteList[s1ValueImageData.spriteIndex].height, iniUIFilename) * ratioHeight);
			s1ValueImageData.colorIndex = GetPrivateProfileInt("Driver Timing.S1.Value", "image.color.id", 1, iniUIFilename) -1;
		}
	}
	
	s1ValueBetterAvailable = GetPrivateProfileInt("Driver Timing.S1.Value.Better", "available", 0, iniUIFilename) != 0;
	if (s1ValueBetterAvailable) {
		s1ValueBetterTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S1.Value.Better", "text.left", -9999, iniUIFilename) * ratioWidth);
		s1ValueBetterTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S1.Value.Better", "text.top", -9999, iniUIFilename) * ratioWidth);
		s1ValueBetterTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Timing.S1.Value.Better", "text.right", -9999, iniUIFilename) * ratioWidth);
		s1ValueBetterTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Timing.S1.Value.Better", "text.bottom", -9999, iniUIFilename) * ratioWidth);
		if (s1ValueBetterTextData.rect.left < 0) s1ValueBetterTextData.rect.left = s1ValueTextData.rect.left;
		if (s1ValueBetterTextData.rect.top < 0) s1ValueBetterTextData.rect.top = s1ValueTextData.rect.top;
		if (s1ValueBetterTextData.rect.right < 0 ) s1ValueBetterTextData.rect.right = s1ValueTextData.rect.right;
		if (s1ValueBetterTextData.rect.bottom < 0) s1ValueBetterTextData.rect.bottom = s1ValueTextData.rect.bottom;

		s1ValueBetterTextData.fontIndex = GetPrivateProfileInt("Driver Timing.S1.Value.Better", "text.font.id", 1, iniUIFilename) - 1;
		s1ValueBetterTextData.colorIndex = GetPrivateProfileInt("Driver Timing.S1.Value.Better", "text.font.color.id", 1, iniUIFilename) - 1;
		s1ValueBetterTextData.alignment = GetPrivateProfileInt("Driver Timing.S1.Value.Better", "text.alignment", 1, iniUIFilename);

		s1ValueBetterImageData.spriteIndex = GetPrivateProfileInt("Driver Timing.S1.Value.Better", "image.id", 0, iniUIFilename) -1;
		if (s1ValueBetterImageData.spriteIndex != -1) {
			s1ValueBetterImageData.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S1.Value.Better", "image.left", 0, iniUIFilename) * ratioWidth);
			s1ValueBetterImageData.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S1.Value.Better", "image.top", 0, iniUIFilename) * ratioHeight);
			s1ValueBetterImageData.width = (int)(GetPrivateProfileInt("Driver Timing.S1.Value.Better", "image.width", (int)spriteList[s1ValueBetterImageData.spriteIndex].width, iniUIFilename) * ratioWidth);
			s1ValueBetterImageData.height = (int)(GetPrivateProfileInt("Driver Timing.S1.Value.Better", "image.height", (int)spriteList[s1ValueBetterImageData.spriteIndex].height, iniUIFilename) * ratioHeight);
			s1ValueBetterImageData.colorIndex = GetPrivateProfileInt("Driver Timing.S1.Value.Better", "image.color.id", 1, iniUIFilename) -1;
		}
	}

	s1ValueWorstAvailable = GetPrivateProfileInt("Driver Timing.S1.Value.Worst", "available", 0, iniUIFilename) != 0;
	if (s1ValueWorstAvailable) {
		s1ValueWorstTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S1.Value.Worst", "text.left", -9999, iniUIFilename) * ratioWidth);
		s1ValueWorstTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S1.Value.Worst", "text.top", -9999, iniUIFilename) * ratioWidth);
		s1ValueWorstTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Timing.S1.Value.Worst", "text.right", -9999, iniUIFilename) * ratioWidth);
		s1ValueWorstTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Timing.S1.Value.Worst", "text.bottom", -9999, iniUIFilename) * ratioWidth);
		if (s1ValueWorstTextData.rect.left < 0) s1ValueWorstTextData.rect.left = s1ValueTextData.rect.left;
		if (s1ValueWorstTextData.rect.top < 0) s1ValueWorstTextData.rect.top = s1ValueTextData.rect.top;
		if (s1ValueWorstTextData.rect.right < 0) s1ValueWorstTextData.rect.right = s1ValueTextData.rect.right;
		if (s1ValueWorstTextData.rect.bottom < 0) s1ValueWorstTextData.rect.bottom = s1ValueTextData.rect.bottom;

		s1ValueWorstTextData.fontIndex = GetPrivateProfileInt("Driver Timing.S1.Value.Worst", "text.font.id", 1, iniUIFilename) - 1;
		s1ValueWorstTextData.colorIndex = GetPrivateProfileInt("Driver Timing.S1.Value.Worst", "text.font.color.id", 1, iniUIFilename) - 1;
		s1ValueWorstTextData.alignment = GetPrivateProfileInt("Driver Timing.S1.Value.Worst", "text.alignment", 1, iniUIFilename);

		s1ValueWorstImageData.spriteIndex = GetPrivateProfileInt("Driver Timing.S1.Value.Worst", "image.id", 0, iniUIFilename) -1;
		if (s1ValueWorstImageData.spriteIndex != -1) {
			s1ValueWorstImageData.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S1.Value.Worst", "image.left", 0, iniUIFilename) * ratioWidth);
			s1ValueWorstImageData.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S1.Value.Worst", "image.top", 0, iniUIFilename) * ratioHeight);
			s1ValueWorstImageData.width = (int)(GetPrivateProfileInt("Driver Timing.S1.Value.Worst", "image.width", (int)spriteList[s1ValueWorstImageData.spriteIndex].width, iniUIFilename) * ratioWidth);
			s1ValueWorstImageData.height = (int)(GetPrivateProfileInt("Driver Timing.S1.Value.Worst", "image.height", (int)spriteList[s1ValueWorstImageData.spriteIndex].height, iniUIFilename) * ratioHeight);
			s1ValueWorstImageData.colorIndex = GetPrivateProfileInt("Driver Timing.S1.Value.Worst", "image.color.id", 1, iniUIFilename) -1;
		}
	}


	////////////////////////////////////////////
	// S2 (S2 + S1)
 	////////////////////////////////////////////
	// S2 Tag
	s2TagAvailable = GetPrivateProfileInt("Driver Timing.S2.Tag", "available", 0, iniUIFilename) != 0;
	if (s2TagAvailable) {
		s2TagTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S2.Tag", "text.left", 0, iniUIFilename) * ratioWidth);
		s2TagTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S2.Tag", "text.top", 0, iniUIFilename) * ratioWidth);
		s2TagTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Timing.S2.Tag", "text.right", 100, iniUIFilename) * ratioWidth);
		s2TagTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Timing.S2.Tag", "text.bottom", 100, iniUIFilename) * ratioWidth);

		s2TagTextData.fontIndex = GetPrivateProfileInt("Driver Timing.S2.Tag", "text.font.id", 1, iniUIFilename) - 1;
		s2TagTextData.colorIndex = GetPrivateProfileInt("Driver Timing.S2.Tag", "text.font.color.id", 1, iniUIFilename) - 1;
		s2TagTextData.alignment = GetPrivateProfileInt("Driver Timing.S2.Tag", "text.alignment", 1, iniUIFilename);

		s2TagImageData.spriteIndex = GetPrivateProfileInt("Driver Timing.S2.Tag", "image.id", 0, iniUIFilename) -1;
		if (s2TagImageData.spriteIndex != -1) {
			s2TagImageData.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S2.Tag", "image.left", 0, iniUIFilename) * ratioWidth);
			s2TagImageData.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S2.Tag", "image.top", 0, iniUIFilename) * ratioHeight);
			s2TagImageData.width = (int)(GetPrivateProfileInt("Driver Timing.S2.Tag", "image.width", (int)spriteList[s2TagImageData.spriteIndex].width, iniUIFilename) * ratioWidth);
			s2TagImageData.height = (int)(GetPrivateProfileInt("Driver Timing.S2.Tag", "image.height", (int)spriteList[s2TagImageData.spriteIndex].height, iniUIFilename) * ratioHeight);
			s2TagImageData.colorIndex = GetPrivateProfileInt("Driver Timing.S2.Tag", "image.color.id", 1, iniUIFilename) -1;
		}
	}
	
	s2TagMyCatAvailable = GetPrivateProfileInt("Driver Timing.S2.Tag.IfBestInCat", "available", 0, iniUIFilename) != 0;
	if (s2TagMyCatAvailable) {
		s2TagMyCatTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S2.Tag.IfBestInCat", "text.left", -9999, iniUIFilename) * ratioWidth);
		s2TagMyCatTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S2.Tag.IfBestInCat", "text.top", -9999, iniUIFilename) * ratioWidth);
		s2TagMyCatTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Timing.S2.Tag.IfBestInCat", "text.right", -9999, iniUIFilename) * ratioWidth);
		s2TagMyCatTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Timing.S2.Tag.IfBestInCat", "text.bottom", -9999, iniUIFilename) * ratioWidth);
		if (s2TagMyCatTextData.rect.left < 0) s2TagMyCatTextData.rect.left = s2TagTextData.rect.left;
		if (s2TagMyCatTextData.rect.top < 0) s2TagMyCatTextData.rect.top = s2TagTextData.rect.top;
		if (s2TagMyCatTextData.rect.right < 0 ) s2TagMyCatTextData.rect.right = s2TagTextData.rect.right;
		if (s2TagMyCatTextData.rect.bottom < 0) s2TagMyCatTextData.rect.bottom = s2TagTextData.rect.bottom;

		s2TagMyCatTextData.fontIndex = GetPrivateProfileInt("Driver Timing.S2.Tag.IfBestInCat", "text.font.id", 1, iniUIFilename) - 1;
		s2TagMyCatTextData.colorIndex = GetPrivateProfileInt("Driver Timing.S2.Tag.IfBestInCat", "text.font.color.id", 1, iniUIFilename) - 1;
		s2TagMyCatTextData.alignment = GetPrivateProfileInt("Driver Timing.S2.Tag.IfBestInCat", "text.alignment", 1, iniUIFilename);

		s2TagMyCatImageData.spriteIndex = GetPrivateProfileInt("Driver Timing.S2.Tag.IfBestInCat", "image.id", 0, iniUIFilename) -1;
		if (s2TagMyCatImageData.spriteIndex != -1) {
			s2TagMyCatImageData.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S2.Tag.IfBestInCat", "image.left", 0, iniUIFilename) * ratioWidth);
			s2TagMyCatImageData.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S2.Tag.IfBestInCat", "image.top", 0, iniUIFilename) * ratioHeight);
			s2TagMyCatImageData.width = (int)(GetPrivateProfileInt("Driver Timing.S2.Tag.IfBestInCat", "image.width", (int)spriteList[s2TagMyCatImageData.spriteIndex].width, iniUIFilename) * ratioWidth);
			s2TagMyCatImageData.height = (int)(GetPrivateProfileInt("Driver Timing.S2.Tag.IfBestInCat", "image.height", (int)spriteList[s2TagMyCatImageData.spriteIndex].height, iniUIFilename) * ratioHeight);
			s2TagMyCatImageData.colorIndex = GetPrivateProfileInt("Driver Timing.S2.Tag.IfBestInCat", "image.color.id", 1, iniUIFilename) -1;
		}
	}

	s2TagAllCatAvailable = GetPrivateProfileInt("Driver Timing.S2.Tag.IfBestAllCat", "available", 0, iniUIFilename) != 0;
	if (s2TagAllCatAvailable) {
		s2TagAllCatTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S2.Tag.IfBestAllCat", "text.left", -9999, iniUIFilename) * ratioWidth);
		s2TagAllCatTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S2.Tag.IfBestAllCat", "text.top", -9999, iniUIFilename) * ratioWidth);
		s2TagAllCatTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Timing.S2.Tag.IfBestAllCat", "text.right", -9999, iniUIFilename) * ratioWidth);
		s2TagAllCatTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Timing.S2.Tag.IfBestAllCat", "text.bottom", -9999, iniUIFilename) * ratioWidth);
		if (s2TagAllCatTextData.rect.left < 0) s2TagAllCatTextData.rect.left = s2TagTextData.rect.left;
		if (s2TagAllCatTextData.rect.top < 0) s2TagAllCatTextData.rect.top = s2TagTextData.rect.top;
		if (s2TagAllCatTextData.rect.right < 0) s2TagAllCatTextData.rect.right = s2TagTextData.rect.right;
		if (s2TagAllCatTextData.rect.bottom < 0) s2TagAllCatTextData.rect.bottom = s2TagTextData.rect.bottom;

		s2TagAllCatTextData.fontIndex = GetPrivateProfileInt("Driver Timing.S2.Tag.IfBestAllCat", "text.font.id", 1, iniUIFilename) - 1;
		s2TagAllCatTextData.colorIndex = GetPrivateProfileInt("Driver Timing.S2.Tag.IfBestAllCat", "text.font.color.id", 1, iniUIFilename) - 1;
		s2TagAllCatTextData.alignment = GetPrivateProfileInt("Driver Timing.S2.Tag.IfBestAllCat", "text.alignment", 1, iniUIFilename);

		s2TagAllCatImageData.spriteIndex = GetPrivateProfileInt("Driver Timing.S2.Tag.IfBestAllCat", "image.id", 0, iniUIFilename) -1;
		if (s2TagAllCatImageData.spriteIndex != -1) {
			s2TagAllCatImageData.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S2.Tag.IfBestAllCat", "image.left", 0, iniUIFilename) * ratioWidth);
			s2TagAllCatImageData.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S2.Tag.IfBestAllCat", "image.top", 0, iniUIFilename) * ratioHeight);
			s2TagAllCatImageData.width = (int)(GetPrivateProfileInt("Driver Timing.S2.Tag.IfBestAllCat", "image.width", (int)spriteList[s2TagAllCatImageData.spriteIndex].width, iniUIFilename) * ratioWidth);
			s2TagAllCatImageData.height = (int)(GetPrivateProfileInt("Driver Timing.S2.Tag.IfBestAllCat", "image.height", (int)spriteList[s2TagAllCatImageData.spriteIndex].height, iniUIFilename) * ratioHeight);
			s2TagAllCatImageData.colorIndex = GetPrivateProfileInt("Driver Timing.S2.Tag.IfBestAllCat", "image.color.id", 1, iniUIFilename) -1;
		}
	}

	// S2 Value
	s2ValueAvailable = GetPrivateProfileInt("Driver Timing.S2.Value", "available", 0, iniUIFilename) != 0;
	if (s2ValueAvailable) {
		s2ValueTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S2.Value", "text.left", 0, iniUIFilename) * ratioWidth);
		s2ValueTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S2.Value", "text.top", 0, iniUIFilename) * ratioWidth);
		s2ValueTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Timing.S2.Value", "text.right", 100, iniUIFilename) * ratioWidth);
		s2ValueTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Timing.S2.Value", "text.bottom", 100, iniUIFilename) * ratioWidth);

		s2ValueTextData.fontIndex = GetPrivateProfileInt("Driver Timing.S2.Value", "text.font.id", 1, iniUIFilename) - 1;
		s2ValueTextData.colorIndex = GetPrivateProfileInt("Driver Timing.S2.Value", "text.font.color.id", 1, iniUIFilename) - 1;
		s2ValueTextData.alignment = GetPrivateProfileInt("Driver Timing.S2.Value", "text.alignment", 1, iniUIFilename);

		s2ValueImageData.spriteIndex = GetPrivateProfileInt("Driver Timing.S2.Value", "image.id", 0, iniUIFilename) -1;
		if (s2ValueImageData.spriteIndex != -1) {
			s2ValueImageData.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S2.Value", "image.left", 0, iniUIFilename) * ratioWidth);
			s2ValueImageData.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S2.Value", "image.top", 0, iniUIFilename) * ratioHeight);
			s2ValueImageData.width = (int)(GetPrivateProfileInt("Driver Timing.S2.Value", "image.width", (int)spriteList[s2ValueImageData.spriteIndex].width, iniUIFilename) * ratioWidth);
			s2ValueImageData.height = (int)(GetPrivateProfileInt("Driver Timing.S2.Value", "image.height", (int)spriteList[s2ValueImageData.spriteIndex].height, iniUIFilename) * ratioHeight);
			s2ValueImageData.colorIndex = GetPrivateProfileInt("Driver Timing.S2.Value", "image.color.id", 1, iniUIFilename) -1;
		}
	}
	
	s2ValueBetterAvailable = GetPrivateProfileInt("Driver Timing.S2.Value.Better", "available", 0, iniUIFilename) != 0;
	if (s2ValueBetterAvailable) {
		s2ValueBetterTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S2.Value.Better", "text.left", -9999, iniUIFilename) * ratioWidth);
		s2ValueBetterTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S2.Value.Better", "text.top", -9999, iniUIFilename) * ratioWidth);
		s2ValueBetterTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Timing.S2.Value.Better", "text.right", -9999, iniUIFilename) * ratioWidth);
		s2ValueBetterTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Timing.S2.Value.Better", "text.bottom", -9999, iniUIFilename) * ratioWidth);
		if (s2ValueBetterTextData.rect.left < 0) s2ValueBetterTextData.rect.left = s2ValueTextData.rect.left;
		if (s2ValueBetterTextData.rect.top < 0) s2ValueBetterTextData.rect.top = s2ValueTextData.rect.top;
		if (s2ValueBetterTextData.rect.right < 0 ) s2ValueBetterTextData.rect.right = s2ValueTextData.rect.right;
		if (s2ValueBetterTextData.rect.bottom < 0) s2ValueBetterTextData.rect.bottom = s2ValueTextData.rect.bottom;

		s2ValueBetterTextData.fontIndex = GetPrivateProfileInt("Driver Timing.S2.Value.Better", "text.font.id", 1, iniUIFilename) - 1;
		s2ValueBetterTextData.colorIndex = GetPrivateProfileInt("Driver Timing.S2.Value.Better", "text.font.color.id", 1, iniUIFilename) - 1;
		s2ValueBetterTextData.alignment = GetPrivateProfileInt("Driver Timing.S2.Value.Better", "text.alignment", 1, iniUIFilename);

		s2ValueBetterImageData.spriteIndex = GetPrivateProfileInt("Driver Timing.S2.Value.Better", "image.id", 0, iniUIFilename) -1;
		if (s2ValueBetterImageData.spriteIndex != -1) {
			s2ValueBetterImageData.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S2.Value.Better", "image.left", 0, iniUIFilename) * ratioWidth);
			s2ValueBetterImageData.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S2.Value.Better", "image.top", 0, iniUIFilename) * ratioHeight);
			s2ValueBetterImageData.width = (int)(GetPrivateProfileInt("Driver Timing.S2.Value.Better", "image.width", (int)spriteList[s2ValueBetterImageData.spriteIndex].width, iniUIFilename) * ratioWidth);
			s2ValueBetterImageData.height = (int)(GetPrivateProfileInt("Driver Timing.S2.Value.Better", "image.height", (int)spriteList[s2ValueBetterImageData.spriteIndex].height, iniUIFilename) * ratioHeight);
			s2ValueBetterImageData.colorIndex = GetPrivateProfileInt("Driver Timing.S2.Value.Better", "image.color.id", 1, iniUIFilename) -1;
		}
	}

	s2ValueWorstAvailable = GetPrivateProfileInt("Driver Timing.S2.Value.Worst", "available", 0, iniUIFilename) != 0;
	if (s2ValueWorstAvailable) {
		s2ValueWorstTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S2.Value.Worst", "text.left", -9999, iniUIFilename) * ratioWidth);
		s2ValueWorstTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S2.Value.Worst", "text.top", -9999, iniUIFilename) * ratioWidth);
		s2ValueWorstTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Timing.S2.Value.Worst", "text.right", -9999, iniUIFilename) * ratioWidth);
		s2ValueWorstTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Timing.S2.Value.Worst", "text.bottom", -9999, iniUIFilename) * ratioWidth);
		if (s2ValueWorstTextData.rect.left < 0) s2ValueWorstTextData.rect.left = s2ValueTextData.rect.left;
		if (s2ValueWorstTextData.rect.top < 0) s2ValueWorstTextData.rect.top = s2ValueTextData.rect.top;
		if (s2ValueWorstTextData.rect.right < 0) s2ValueWorstTextData.rect.right = s2ValueTextData.rect.right;
		if (s2ValueWorstTextData.rect.bottom < 0) s2ValueWorstTextData.rect.bottom = s2ValueTextData.rect.bottom;

		s2ValueWorstTextData.fontIndex = GetPrivateProfileInt("Driver Timing.S2.Value.Worst", "text.font.id", 1, iniUIFilename) - 1;
		s2ValueWorstTextData.colorIndex = GetPrivateProfileInt("Driver Timing.S2.Value.Worst", "text.font.color.id", 1, iniUIFilename) - 1;
		s2ValueWorstTextData.alignment = GetPrivateProfileInt("Driver Timing.S2.Value.Worst", "text.alignment", 1, iniUIFilename);

		s2ValueWorstImageData.spriteIndex = GetPrivateProfileInt("Driver Timing.S2.Value.Worst", "image.id", 0, iniUIFilename) -1;
		if (s2ValueWorstImageData.spriteIndex != -1) {
			s2ValueWorstImageData.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S2.Value.Worst", "image.left", 0, iniUIFilename) * ratioWidth);
			s2ValueWorstImageData.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S2.Value.Worst", "image.top", 0, iniUIFilename) * ratioHeight);
			s2ValueWorstImageData.width = (int)(GetPrivateProfileInt("Driver Timing.S2.Value.Worst", "image.width", (int)spriteList[s2ValueWorstImageData.spriteIndex].width, iniUIFilename) * ratioWidth);
			s2ValueWorstImageData.height = (int)(GetPrivateProfileInt("Driver Timing.S2.Value.Worst", "image.height", (int)spriteList[s2ValueWorstImageData.spriteIndex].height, iniUIFilename) * ratioHeight);
			s2ValueWorstImageData.colorIndex = GetPrivateProfileInt("Driver Timing.S2.Value.Worst", "image.color.id", 1, iniUIFilename) -1;
		}
	}

	////////////////////////////////////////////
	// S3 (Laptime)
 	////////////////////////////////////////////
	// S3 Tag
	s3TagAvailable = GetPrivateProfileInt("Driver Timing.S3.Tag", "available", 0, iniUIFilename) != 0;
	if (s3TagAvailable) {
		s3TagTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S3.Tag", "text.left", 0, iniUIFilename) * ratioWidth);
		s3TagTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S3.Tag", "text.top", 0, iniUIFilename) * ratioWidth);
		s3TagTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Timing.S3.Tag", "text.right", 100, iniUIFilename) * ratioWidth);
		s3TagTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Timing.S3.Tag", "text.bottom", 100, iniUIFilename) * ratioWidth);

		s3TagTextData.fontIndex = GetPrivateProfileInt("Driver Timing.S3.Tag", "text.font.id", 1, iniUIFilename) - 1;
		s3TagTextData.colorIndex = GetPrivateProfileInt("Driver Timing.S3.Tag", "text.font.color.id", 1, iniUIFilename) - 1;
		s3TagTextData.alignment = GetPrivateProfileInt("Driver Timing.S3.Tag", "text.alignment", 1, iniUIFilename);

		s3TagImageData.spriteIndex = GetPrivateProfileInt("Driver Timing.S3.Tag", "image.id", 0, iniUIFilename) -1;
		if (s3TagImageData.spriteIndex != -1) {
			s3TagImageData.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S3.Tag", "image.left", 0, iniUIFilename) * ratioWidth);
			s3TagImageData.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S3.Tag", "image.top", 0, iniUIFilename) * ratioHeight);
			s3TagImageData.width = (int)(GetPrivateProfileInt("Driver Timing.S3.Tag", "image.width", (int)spriteList[s3TagImageData.spriteIndex].width, iniUIFilename) * ratioWidth);
			s3TagImageData.height = (int)(GetPrivateProfileInt("Driver Timing.S3.Tag", "image.height", (int)spriteList[s3TagImageData.spriteIndex].height, iniUIFilename) * ratioHeight);
			s3TagImageData.colorIndex = GetPrivateProfileInt("Driver Timing.S3.Tag", "image.color.id", 1, iniUIFilename) -1;
		}
	}
	
	s3TagMyCatAvailable = GetPrivateProfileInt("Driver Timing.S3.Tag.IfBestInCat", "available", 0, iniUIFilename) != 0;
	if (s3TagMyCatAvailable) {
		s3TagMyCatTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S3.Tag.IfBestInCat", "text.left", -9999, iniUIFilename) * ratioWidth);
		s3TagMyCatTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S3.Tag.IfBestInCat", "text.top", -9999, iniUIFilename) * ratioWidth);
		s3TagMyCatTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Timing.S3.Tag.IfBestInCat", "text.right", -9999, iniUIFilename) * ratioWidth);
		s3TagMyCatTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Timing.S3.Tag.IfBestInCat", "text.bottom", -9999, iniUIFilename) * ratioWidth);
		if (s3TagMyCatTextData.rect.left < 0) s3TagMyCatTextData.rect.left = s3TagTextData.rect.left;
		if (s3TagMyCatTextData.rect.top < 0) s3TagMyCatTextData.rect.top = s3TagTextData.rect.top;
		if (s3TagMyCatTextData.rect.right < 0 ) s3TagMyCatTextData.rect.right = s3TagTextData.rect.right;
		if (s3TagMyCatTextData.rect.bottom < 0) s3TagMyCatTextData.rect.bottom = s3TagTextData.rect.bottom;

		s3TagMyCatTextData.fontIndex = GetPrivateProfileInt("Driver Timing.S3.Tag.IfBestInCat", "text.font.id", 1, iniUIFilename) - 1;
		s3TagMyCatTextData.colorIndex = GetPrivateProfileInt("Driver Timing.S3.Tag.IfBestInCat", "text.font.color.id", 1, iniUIFilename) - 1;
		s3TagMyCatTextData.alignment = GetPrivateProfileInt("Driver Timing.S3.Tag.IfBestInCat", "text.alignment", 1, iniUIFilename);

		s3TagMyCatImageData.spriteIndex = GetPrivateProfileInt("Driver Timing.S3.Tag.IfBestInCat", "image.id", 0, iniUIFilename) -1;
		if (s3TagMyCatImageData.spriteIndex != -1) {
			s3TagMyCatImageData.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S3.Tag.IfBestInCat", "image.left", 0, iniUIFilename) * ratioWidth);
			s3TagMyCatImageData.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S3.Tag.IfBestInCat", "image.top", 0, iniUIFilename) * ratioHeight);
			s3TagMyCatImageData.width = (int)(GetPrivateProfileInt("Driver Timing.S3.Tag.IfBestInCat", "image.width", (int)spriteList[s3TagMyCatImageData.spriteIndex].width, iniUIFilename) * ratioWidth);
			s3TagMyCatImageData.height = (int)(GetPrivateProfileInt("Driver Timing.S3.Tag.IfBestInCat", "image.height", (int)spriteList[s3TagMyCatImageData.spriteIndex].height, iniUIFilename) * ratioHeight);
			s3TagMyCatImageData.colorIndex = GetPrivateProfileInt("Driver Timing.S3.Tag.IfBestInCat", "image.color.id", 1, iniUIFilename) -1;
		}
	}

	s3TagAllCatAvailable = GetPrivateProfileInt("Driver Timing.S3.Tag.IfBestAllCat", "available", 0, iniUIFilename) != 0;
	if (s3TagAllCatAvailable) {
		s3TagAllCatTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S3.Tag.IfBestAllCat", "text.left", -9999, iniUIFilename) * ratioWidth);
		s3TagAllCatTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S3.Tag.IfBestAllCat", "text.top", -9999, iniUIFilename) * ratioWidth);
		s3TagAllCatTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Timing.S3.Tag.IfBestAllCat", "text.right", -9999, iniUIFilename) * ratioWidth);
		s3TagAllCatTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Timing.S3.Tag.IfBestAllCat", "text.bottom", -9999, iniUIFilename) * ratioWidth);
		if (s3TagAllCatTextData.rect.left < 0) s3TagAllCatTextData.rect.left = s3TagTextData.rect.left;
		if (s3TagAllCatTextData.rect.top < 0) s3TagAllCatTextData.rect.top = s3TagTextData.rect.top;
		if (s3TagAllCatTextData.rect.right < 0) s3TagAllCatTextData.rect.right = s3TagTextData.rect.right;
		if (s3TagAllCatTextData.rect.bottom < 0) s3TagAllCatTextData.rect.bottom = s3TagTextData.rect.bottom;

		s3TagAllCatTextData.fontIndex = GetPrivateProfileInt("Driver Timing.S3.Tag.IfBestAllCat", "text.font.id", 1, iniUIFilename) - 1;
		s3TagAllCatTextData.colorIndex = GetPrivateProfileInt("Driver Timing.S3.Tag.IfBestAllCat", "text.font.color.id", 1, iniUIFilename) - 1;
		s3TagAllCatTextData.alignment = GetPrivateProfileInt("Driver Timing.S3.Tag.IfBestAllCat", "text.alignment", 1, iniUIFilename);

		s3TagAllCatImageData.spriteIndex = GetPrivateProfileInt("Driver Timing.S3.Tag.IfBestAllCat", "image.id", 0, iniUIFilename) -1;
		if (s3TagAllCatImageData.spriteIndex != -1) {
			s3TagAllCatImageData.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S3.Tag.IfBestAllCat", "image.left", 0, iniUIFilename) * ratioWidth);
			s3TagAllCatImageData.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S3.Tag.IfBestAllCat", "image.top", 0, iniUIFilename) * ratioHeight);
			s3TagAllCatImageData.width = (int)(GetPrivateProfileInt("Driver Timing.S3.Tag.IfBestAllCat", "image.width", (int)spriteList[s3TagAllCatImageData.spriteIndex].width, iniUIFilename) * ratioWidth);
			s3TagAllCatImageData.height = (int)(GetPrivateProfileInt("Driver Timing.S3.Tag.IfBestAllCat", "image.height", (int)spriteList[s3TagAllCatImageData.spriteIndex].height, iniUIFilename) * ratioHeight);
			s3TagAllCatImageData.colorIndex = GetPrivateProfileInt("Driver Timing.S3.Tag.IfBestAllCat", "image.color.id", 1, iniUIFilename) -1;
		}
	}

	// S3 Value
	s3ValueAvailable = GetPrivateProfileInt("Driver Timing.S3.Value", "available", 0, iniUIFilename) != 0;
	if (s3ValueAvailable) {
		s3ValueTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S3.Value", "text.left", 0, iniUIFilename) * ratioWidth);
		s3ValueTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S3.Value", "text.top", 0, iniUIFilename) * ratioWidth);
		s3ValueTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Timing.S3.Value", "text.right", 100, iniUIFilename) * ratioWidth);
		s3ValueTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Timing.S3.Value", "text.bottom", 100, iniUIFilename) * ratioWidth);

		s3ValueTextData.fontIndex = GetPrivateProfileInt("Driver Timing.S3.Value", "text.font.id", 1, iniUIFilename) - 1;
		s3ValueTextData.colorIndex = GetPrivateProfileInt("Driver Timing.S3.Value", "text.font.color.id", 1, iniUIFilename) - 1;
		s3ValueTextData.alignment = GetPrivateProfileInt("Driver Timing.S3.Value", "text.alignment", 1, iniUIFilename);

		s3ValueImageData.spriteIndex = GetPrivateProfileInt("Driver Timing.S3.Value", "image.id", 0, iniUIFilename) -1;
		if (s3ValueImageData.spriteIndex != -1) {
			s3ValueImageData.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S3.Value", "image.left", 0, iniUIFilename) * ratioWidth);
			s3ValueImageData.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S3.Value", "image.top", 0, iniUIFilename) * ratioHeight);
			s3ValueImageData.width = (int)(GetPrivateProfileInt("Driver Timing.S3.Value", "image.width", (int)spriteList[s3ValueImageData.spriteIndex].width, iniUIFilename) * ratioWidth);
			s3ValueImageData.height = (int)(GetPrivateProfileInt("Driver Timing.S3.Value", "image.height", (int)spriteList[s3ValueImageData.spriteIndex].height, iniUIFilename) * ratioHeight);
			s3ValueImageData.colorIndex = GetPrivateProfileInt("Driver Timing.S3.Value", "image.color.id", 1, iniUIFilename) -1;
		}
	}
	
	s3ValueBetterAvailable = GetPrivateProfileInt("Driver Timing.S3.Value.Better", "available", 0, iniUIFilename) != 0;
	if (s3ValueBetterAvailable) {
		s3ValueBetterTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S3.Value.Better", "text.left", -9999, iniUIFilename) * ratioWidth);
		s3ValueBetterTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S3.Value.Better", "text.top", -9999, iniUIFilename) * ratioWidth);
		s3ValueBetterTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Timing.S3.Value.Better", "text.right", -9999, iniUIFilename) * ratioWidth);
		s3ValueBetterTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Timing.S3.Value.Better", "text.bottom", -9999, iniUIFilename) * ratioWidth);
		if (s3ValueBetterTextData.rect.left < 0) s3ValueBetterTextData.rect.left = s3ValueTextData.rect.left;
		if (s3ValueBetterTextData.rect.top < 0) s3ValueBetterTextData.rect.top = s3ValueTextData.rect.top;
		if (s3ValueBetterTextData.rect.right < 0 ) s3ValueBetterTextData.rect.right = s3ValueTextData.rect.right;
		if (s3ValueBetterTextData.rect.bottom < 0) s3ValueBetterTextData.rect.bottom = s3ValueTextData.rect.bottom;

		s3ValueBetterTextData.fontIndex = GetPrivateProfileInt("Driver Timing.S3.Value.Better", "text.font.id", 1, iniUIFilename) - 1;
		s3ValueBetterTextData.colorIndex = GetPrivateProfileInt("Driver Timing.S3.Value.Better", "text.font.color.id", 1, iniUIFilename) - 1;
		s3ValueBetterTextData.alignment = GetPrivateProfileInt("Driver Timing.S3.Value.Better", "text.alignment", 1, iniUIFilename);

		s3ValueBetterImageData.spriteIndex = GetPrivateProfileInt("Driver Timing.S3.Value.Better", "image.id", 0, iniUIFilename) -1;
		if (s3ValueBetterImageData.spriteIndex != -1) {
			s3ValueBetterImageData.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S3.Value.Better", "image.left", 0, iniUIFilename) * ratioWidth);
			s3ValueBetterImageData.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S3.Value.Better", "image.top", 0, iniUIFilename) * ratioHeight);
			s3ValueBetterImageData.width = (int)(GetPrivateProfileInt("Driver Timing.S3.Value.Better", "image.width", (int)spriteList[s3ValueBetterImageData.spriteIndex].width, iniUIFilename) * ratioWidth);
			s3ValueBetterImageData.height = (int)(GetPrivateProfileInt("Driver Timing.S3.Value.Better", "image.height", (int)spriteList[s3ValueBetterImageData.spriteIndex].height, iniUIFilename) * ratioHeight);
			s3ValueBetterImageData.colorIndex = GetPrivateProfileInt("Driver Timing.S3.Value.Better", "image.color.id", 1, iniUIFilename) -1;
		}
	}

	s3ValueWorstAvailable = GetPrivateProfileInt("Driver Timing.S3.Value.Worst", "available", 0, iniUIFilename) != 0;
	if (s3ValueWorstAvailable) {
		s3ValueWorstTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S3.Value.Worst", "text.left", -9999, iniUIFilename) * ratioWidth);
		s3ValueWorstTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S3.Value.Worst", "text.top", -9999, iniUIFilename) * ratioWidth);
		s3ValueWorstTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Timing.S3.Value.Worst", "text.right", -9999, iniUIFilename) * ratioWidth);
		s3ValueWorstTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Timing.S3.Value.Worst", "text.bottom", -9999, iniUIFilename) * ratioWidth);
		if (s3ValueWorstTextData.rect.left < 0) s3ValueWorstTextData.rect.left = s3ValueTextData.rect.left;
		if (s3ValueWorstTextData.rect.top < 0) s3ValueWorstTextData.rect.top = s3ValueTextData.rect.top;
		if (s3ValueWorstTextData.rect.right < 0) s3ValueWorstTextData.rect.right = s3ValueTextData.rect.right;
		if (s3ValueWorstTextData.rect.bottom < 0) s3ValueWorstTextData.rect.bottom = s3ValueTextData.rect.bottom;

		s3ValueWorstTextData.fontIndex = GetPrivateProfileInt("Driver Timing.S3.Value.Worst", "text.font.id", 1, iniUIFilename) - 1;
		s3ValueWorstTextData.colorIndex = GetPrivateProfileInt("Driver Timing.S3.Value.Worst", "text.font.color.id", 1, iniUIFilename) - 1;
		s3ValueWorstTextData.alignment = GetPrivateProfileInt("Driver Timing.S3.Value.Worst", "text.alignment", 1, iniUIFilename);

		s3ValueWorstImageData.spriteIndex = GetPrivateProfileInt("Driver Timing.S3.Value.Worst", "image.id", 0, iniUIFilename) -1;
		if (s3ValueWorstImageData.spriteIndex != -1) {
			s3ValueWorstImageData.left = (int)(posX + GetPrivateProfileInt("Driver Timing.S3.Value.Worst", "image.left", 0, iniUIFilename) * ratioWidth);
			s3ValueWorstImageData.top = (int)(posY + GetPrivateProfileInt("Driver Timing.S3.Value.Worst", "image.top", 0, iniUIFilename) * ratioHeight);
			s3ValueWorstImageData.width = (int)(GetPrivateProfileInt("Driver Timing.S3.Value.Worst", "image.width", (int)spriteList[s3ValueWorstImageData.spriteIndex].width, iniUIFilename) * ratioWidth);
			s3ValueWorstImageData.height = (int)(GetPrivateProfileInt("Driver Timing.S3.Value.Worst", "image.height", (int)spriteList[s3ValueWorstImageData.spriteIndex].height, iniUIFilename) * ratioHeight);
			s3ValueWorstImageData.colorIndex = GetPrivateProfileInt("Driver Timing.S3.Value.Worst", "image.color.id", 1, iniUIFilename) -1;
		}
	}

	/////////////////////////////////////////////////////
	// Gap
	/////////////////////////////////////////////////////
	gapValueAvailable = GetPrivateProfileInt("Driver Timing.Gap", "available", 0, iniUIFilename) != 0;
	if (gapValueAvailable) {
		gapValueTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Timing.Gap", "text.left", 0, iniUIFilename) * ratioWidth);
		gapValueTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Timing.Gap", "text.top", 0, iniUIFilename) * ratioWidth);
		gapValueTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Timing.Gap", "text.right", 100, iniUIFilename) * ratioWidth);
		gapValueTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Timing.Gap", "text.bottom", 100, iniUIFilename) * ratioWidth);

		gapValueTextData.fontIndex = GetPrivateProfileInt("Driver Timing.Gap", "text.font.id", 1, iniUIFilename) - 1;
		gapValueTextData.colorIndex = GetPrivateProfileInt("Driver Timing.Gap", "text.font.color.id", 1, iniUIFilename) - 1;
		gapValueTextData.alignment = GetPrivateProfileInt("Driver Timing.Gap", "text.alignment", 1, iniUIFilename);

		gapValueImageData.spriteIndex = GetPrivateProfileInt("Driver Timing.Gap", "image.id", 0, iniUIFilename) -1;
		if (gapValueImageData.spriteIndex != -1) {
			gapValueImageData.left = (int)(posX + GetPrivateProfileInt("Driver Timing.Gap", "image.left", 0, iniUIFilename) * ratioWidth);
			gapValueImageData.top = (int)(posY + GetPrivateProfileInt("Driver Timing.Gap", "image.top", 0, iniUIFilename) * ratioHeight);
			gapValueImageData.width = (int)(GetPrivateProfileInt("Driver Timing.Gap", "image.width", (int)spriteList[gapValueImageData.spriteIndex].width, iniUIFilename) * ratioWidth);
			gapValueImageData.height = (int)(GetPrivateProfileInt("Driver Timing.Gap", "image.height", (int)spriteList[gapValueImageData.spriteIndex].height, iniUIFilename) * ratioHeight);
			gapValueImageData.colorIndex = GetPrivateProfileInt("Driver Timing.Gap", "image.color.id", 1, iniUIFilename) -1;
		}
	}
	
	gapValueBetterAvailable = GetPrivateProfileInt("Driver Timing.Gap.Better", "available", 0, iniUIFilename) != 0;
	if (gapValueBetterAvailable) {
		gapValueBetterTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Timing.Gap.Better", "text.left", -9999, iniUIFilename) * ratioWidth);
		gapValueBetterTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Timing.Gap.Better", "text.top", -9999, iniUIFilename) * ratioWidth);
		gapValueBetterTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Timing.Gap.Better", "text.right", -9999, iniUIFilename) * ratioWidth);
		gapValueBetterTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Timing.Gap.Better", "text.bottom", -9999, iniUIFilename) * ratioWidth);
		if (gapValueBetterTextData.rect.left < 0) gapValueBetterTextData.rect.left = gapValueTextData.rect.left;
		if (gapValueBetterTextData.rect.top < 0) gapValueBetterTextData.rect.top = gapValueTextData.rect.top;
		if (gapValueBetterTextData.rect.right < 0 ) gapValueBetterTextData.rect.right = gapValueTextData.rect.right;
		if (gapValueBetterTextData.rect.bottom < 0) gapValueBetterTextData.rect.bottom = gapValueTextData.rect.bottom;

		gapValueBetterTextData.fontIndex = GetPrivateProfileInt("Driver Timing.Gap.Better", "text.font.id", 1, iniUIFilename) - 1;
		gapValueBetterTextData.colorIndex = GetPrivateProfileInt("Driver Timing.Gap.Better", "text.font.color.id", 1, iniUIFilename) - 1;
		gapValueBetterTextData.alignment = GetPrivateProfileInt("Driver Timing.Gap.Better", "text.alignment", 1, iniUIFilename);

		gapValueBetterImageData.spriteIndex = GetPrivateProfileInt("Driver Timing.Gap.Better", "image.id", 0, iniUIFilename) -1;
		if (gapValueBetterImageData.spriteIndex != -1) {
			gapValueBetterImageData.left = (int)(posX + GetPrivateProfileInt("Driver Timing.Gap.Better", "image.left", 0, iniUIFilename) * ratioWidth);
			gapValueBetterImageData.top = (int)(posY + GetPrivateProfileInt("Driver Timing.Gap.Better", "image.top", 0, iniUIFilename) * ratioHeight);
			gapValueBetterImageData.width = (int)(GetPrivateProfileInt("Driver Timing.Gap.Better", "image.width", (int)spriteList[gapValueBetterImageData.spriteIndex].width, iniUIFilename) * ratioWidth);
			gapValueBetterImageData.height = (int)(GetPrivateProfileInt("Driver Timing.Gap.Better", "image.height", (int)spriteList[gapValueBetterImageData.spriteIndex].height, iniUIFilename) * ratioHeight);
			gapValueBetterImageData.colorIndex = GetPrivateProfileInt("Driver Timing.Gap.Better", "image.color.id", 1, iniUIFilename) -1;
		}
	}

	gapValueWorstAvailable = GetPrivateProfileInt("Driver Timing.Gap.Worst", "available", 0, iniUIFilename) != 0;
	if (gapValueWorstAvailable) {
		gapValueWorstTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Timing.Gap.Worst", "text.left", -9999, iniUIFilename) * ratioWidth);
		gapValueWorstTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Timing.Gap.Worst", "text.top", -9999, iniUIFilename) * ratioWidth);
		gapValueWorstTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Timing.Gap.Worst", "text.right", -9999, iniUIFilename) * ratioWidth);
		gapValueWorstTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Timing.Gap.Worst", "text.bottom", -9999, iniUIFilename) * ratioWidth);
		if (gapValueWorstTextData.rect.left < 0) gapValueWorstTextData.rect.left = gapValueTextData.rect.left;
		if (gapValueWorstTextData.rect.top < 0) gapValueWorstTextData.rect.top = gapValueTextData.rect.top;
		if (gapValueWorstTextData.rect.right < 0) gapValueWorstTextData.rect.right = gapValueTextData.rect.right;
		if (gapValueWorstTextData.rect.bottom < 0) gapValueWorstTextData.rect.bottom = gapValueTextData.rect.bottom;

		gapValueWorstTextData.fontIndex = GetPrivateProfileInt("Driver Timing.Gap.Worst", "text.font.id", 1, iniUIFilename) - 1;
		gapValueWorstTextData.colorIndex = GetPrivateProfileInt("Driver Timing.Gap.Worst", "text.font.color.id", 1, iniUIFilename) - 1;
		gapValueWorstTextData.alignment = GetPrivateProfileInt("Driver Timing.Gap.Worst", "text.alignment", 1, iniUIFilename);

		gapValueWorstImageData.spriteIndex = GetPrivateProfileInt("Driver Timing.Gap.Worst", "image.id", 0, iniUIFilename) -1;
		if (gapValueWorstImageData.spriteIndex != -1) {
			gapValueWorstImageData.left = (int)(posX + GetPrivateProfileInt("Driver Timing.Gap.Worst", "image.left", 0, iniUIFilename) * ratioWidth);
			gapValueWorstImageData.top = (int)(posY + GetPrivateProfileInt("Driver Timing.Gap.Worst", "image.top", 0, iniUIFilename) * ratioHeight);
			gapValueWorstImageData.width = (int)(GetPrivateProfileInt("Driver Timing.Gap.Worst", "image.width", (int)spriteList[gapValueWorstImageData.spriteIndex].width, iniUIFilename) * ratioWidth);
			gapValueWorstImageData.height = (int)(GetPrivateProfileInt("Driver Timing.Gap.Worst", "image.height", (int)spriteList[gapValueWorstImageData.spriteIndex].height, iniUIFilename) * ratioHeight);
			gapValueWorstImageData.colorIndex = GetPrivateProfileInt("Driver Timing.Gap.Worst", "image.color.id", 1, iniUIFilename) -1;
		}
	}

	/////////////////////////////////////////////////////
	// Laptime
	/////////////////////////////////////////////////////
	laptimeValueAvailable = GetPrivateProfileInt("Driver Timing.Laptime", "available", 0, iniUIFilename) != 0;
	if (laptimeValueAvailable) {
		laptimeValueTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Timing.Laptime", "text.left", 0, iniUIFilename) * ratioWidth);
		laptimeValueTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Timing.Laptime", "text.top", 0, iniUIFilename) * ratioWidth);
		laptimeValueTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Timing.Laptime", "text.right", 100, iniUIFilename) * ratioWidth);
		laptimeValueTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Timing.Laptime", "text.bottom", 100, iniUIFilename) * ratioWidth);

		laptimeValueTextData.fontIndex = GetPrivateProfileInt("Driver Timing.Laptime", "text.font.id", 1, iniUIFilename) - 1;
		laptimeValueTextData.colorIndex = GetPrivateProfileInt("Driver Timing.Laptime", "text.font.color.id", 1, iniUIFilename) - 1;
		laptimeValueTextData.alignment = GetPrivateProfileInt("Driver Timing.Laptime", "text.alignment", 1, iniUIFilename);

		laptimeValueImageData.spriteIndex = GetPrivateProfileInt("Driver Timing.Laptime", "image.id", 0, iniUIFilename) -1;
		if (laptimeValueImageData.spriteIndex != -1) {
			laptimeValueImageData.left = (int)(posX + GetPrivateProfileInt("Driver Timing.Laptime", "image.left", 0, iniUIFilename) * ratioWidth);
			laptimeValueImageData.top = (int)(posY + GetPrivateProfileInt("Driver Timing.Laptime", "image.top", 0, iniUIFilename) * ratioHeight);
			laptimeValueImageData.width = (int)(GetPrivateProfileInt("Driver Timing.Laptime", "image.width", (int)spriteList[laptimeValueImageData.spriteIndex].width, iniUIFilename) * ratioWidth);
			laptimeValueImageData.height = (int)(GetPrivateProfileInt("Driver Timing.Laptime", "image.height", (int)spriteList[laptimeValueImageData.spriteIndex].height, iniUIFilename) * ratioHeight);
			laptimeValueImageData.colorIndex = GetPrivateProfileInt("Driver Timing.Laptime", "image.color.id", 1, iniUIFilename) -1;
		}
	}
	
	laptimeValueBetterAvailable = GetPrivateProfileInt("Driver Timing.Laptime.Better", "available", 0, iniUIFilename) != 0;
	if (laptimeValueBetterAvailable) {
		laptimeValueBetterTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Timing.Laptime.Better", "text.left", -9999, iniUIFilename) * ratioWidth);
		laptimeValueBetterTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Timing.Laptime.Better", "text.top", -9999, iniUIFilename) * ratioWidth);
		laptimeValueBetterTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Timing.Laptime.Better", "text.right", -9999, iniUIFilename) * ratioWidth);
		laptimeValueBetterTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Timing.Laptime.Better", "text.bottom", -9999, iniUIFilename) * ratioWidth);
		if (laptimeValueBetterTextData.rect.left < 0) laptimeValueBetterTextData.rect.left = laptimeValueTextData.rect.left;
		if (laptimeValueBetterTextData.rect.top < 0) laptimeValueBetterTextData.rect.top = laptimeValueTextData.rect.top;
		if (laptimeValueBetterTextData.rect.right < 0 ) laptimeValueBetterTextData.rect.right = laptimeValueTextData.rect.right;
		if (laptimeValueBetterTextData.rect.bottom < 0) laptimeValueBetterTextData.rect.bottom = laptimeValueTextData.rect.bottom;

		laptimeValueBetterTextData.fontIndex = GetPrivateProfileInt("Driver Timing.Laptime.Better", "text.font.id", 1, iniUIFilename) - 1;
		laptimeValueBetterTextData.colorIndex = GetPrivateProfileInt("Driver Timing.Laptime.Better", "text.font.color.id", 1, iniUIFilename) - 1;
		laptimeValueBetterTextData.alignment = GetPrivateProfileInt("Driver Timing.Laptime.Better", "text.alignment", 1, iniUIFilename);

		laptimeValueBetterImageData.spriteIndex = GetPrivateProfileInt("Driver Timing.Laptime.Better", "image.id", 0, iniUIFilename) -1;
		if (laptimeValueBetterImageData.spriteIndex != -1) {
			laptimeValueBetterImageData.left = (int)(posX + GetPrivateProfileInt("Driver Timing.Laptime.Better", "image.left", 0, iniUIFilename) * ratioWidth);
			laptimeValueBetterImageData.top = (int)(posY + GetPrivateProfileInt("Driver Timing.Laptime.Better", "image.top", 0, iniUIFilename) * ratioHeight);
			laptimeValueBetterImageData.width = (int)(GetPrivateProfileInt("Driver Timing.Laptime.Better", "image.width", (int)spriteList[laptimeValueBetterImageData.spriteIndex].width, iniUIFilename) * ratioWidth);
			laptimeValueBetterImageData.height = (int)(GetPrivateProfileInt("Driver Timing.Laptime.Better", "image.height", (int)spriteList[laptimeValueBetterImageData.spriteIndex].height, iniUIFilename) * ratioHeight);
			laptimeValueBetterImageData.colorIndex = GetPrivateProfileInt("Driver Timing.Laptime.Better", "image.color.id", 1, iniUIFilename) -1;
		}
	}

	laptimeValueWorstAvailable = GetPrivateProfileInt("Driver Timing.Laptime.Worst", "available", 0, iniUIFilename) != 0;
	if (laptimeValueWorstAvailable) {
		laptimeValueWorstTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Timing.Laptime.Worst", "text.left", -9999, iniUIFilename) * ratioWidth);
		laptimeValueWorstTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Timing.Laptime.Worst", "text.top", -9999, iniUIFilename) * ratioWidth);
		laptimeValueWorstTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Timing.Laptime.Worst", "text.right", -9999, iniUIFilename) * ratioWidth);
		laptimeValueWorstTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Timing.Laptime.Worst", "text.bottom", -9999, iniUIFilename) * ratioWidth);
		if (laptimeValueWorstTextData.rect.left < 0) laptimeValueWorstTextData.rect.left = laptimeValueTextData.rect.left;
		if (laptimeValueWorstTextData.rect.top < 0) laptimeValueWorstTextData.rect.top = laptimeValueTextData.rect.top;
		if (laptimeValueWorstTextData.rect.right < 0) laptimeValueWorstTextData.rect.right = laptimeValueTextData.rect.right;
		if (laptimeValueWorstTextData.rect.bottom < 0) laptimeValueWorstTextData.rect.bottom = laptimeValueTextData.rect.bottom;

		laptimeValueWorstTextData.fontIndex = GetPrivateProfileInt("Driver Timing.Laptime.Worst", "text.font.id", 1, iniUIFilename) - 1;
		laptimeValueWorstTextData.colorIndex = GetPrivateProfileInt("Driver Timing.Laptime.Worst", "text.font.color.id", 1, iniUIFilename) - 1;
		laptimeValueWorstTextData.alignment = GetPrivateProfileInt("Driver Timing.Laptime.Worst", "text.alignment", 1, iniUIFilename);

		laptimeValueWorstImageData.spriteIndex = GetPrivateProfileInt("Driver Timing.Laptime.Worst", "image.id", 0, iniUIFilename) -1;
		if (laptimeValueWorstImageData.spriteIndex != -1) {
			laptimeValueWorstImageData.left = (int)(posX + GetPrivateProfileInt("Driver Timing.Laptime.Worst", "image.left", 0, iniUIFilename) * ratioWidth);
			laptimeValueWorstImageData.top = (int)(posY + GetPrivateProfileInt("Driver Timing.Laptime.Worst", "image.top", 0, iniUIFilename) * ratioHeight);
			laptimeValueWorstImageData.width = (int)(GetPrivateProfileInt("Driver Timing.Laptime.Worst", "image.width", (int)spriteList[laptimeValueWorstImageData.spriteIndex].width, iniUIFilename) * ratioWidth);
			laptimeValueWorstImageData.height = (int)(GetPrivateProfileInt("Driver Timing.Laptime.Worst", "image.height", (int)spriteList[laptimeValueWorstImageData.spriteIndex].height, iniUIFilename) * ratioHeight);
			laptimeValueWorstImageData.colorIndex = GetPrivateProfileInt("Driver Timing.Laptime.Worst", "image.color.id", 1, iniUIFilename) -1;
		}
	}

	laptimeValueBestAvailable = GetPrivateProfileInt("Driver Timing.Laptime.Best", "available", 0, iniUIFilename) != 0;
	if (laptimeValueBestAvailable) {
		laptimeValueBestTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Timing.Laptime.Best", "text.left", -9999, iniUIFilename) * ratioWidth);
		laptimeValueBestTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Timing.Laptime.Best", "text.top", -9999, iniUIFilename) * ratioWidth);
		laptimeValueBestTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Timing.Laptime.Best", "text.right", -9999, iniUIFilename) * ratioWidth);
		laptimeValueBestTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Timing.Laptime.Best", "text.bottom", -9999, iniUIFilename) * ratioWidth);
		if (laptimeValueBestTextData.rect.left < 0) laptimeValueBestTextData.rect.left = laptimeValueTextData.rect.left;
		if (laptimeValueBestTextData.rect.top < 0) laptimeValueBestTextData.rect.top = laptimeValueTextData.rect.top;
		if (laptimeValueBestTextData.rect.right < 0) laptimeValueBestTextData.rect.right = laptimeValueTextData.rect.right;
		if (laptimeValueBestTextData.rect.bottom < 0) laptimeValueBestTextData.rect.bottom = laptimeValueTextData.rect.bottom;

		laptimeValueBestTextData.fontIndex = GetPrivateProfileInt("Driver Timing.Laptime.Best", "text.font.id", 1, iniUIFilename) - 1;
		laptimeValueBestTextData.colorIndex = GetPrivateProfileInt("Driver Timing.Laptime.Best", "text.font.color.id", 1, iniUIFilename) - 1;
		laptimeValueBestTextData.alignment = GetPrivateProfileInt("Driver Timing.Laptime.Best", "text.alignment", 1, iniUIFilename);

		laptimeValueBestImageData.spriteIndex = GetPrivateProfileInt("Driver Timing.Laptime.Best", "image.id", 0, iniUIFilename) -1;
		if (laptimeValueBestImageData.spriteIndex != -1) {
			laptimeValueBestImageData.left = (int)(posX + GetPrivateProfileInt("Driver Timing.Laptime.Best", "image.left", 0, iniUIFilename) * ratioWidth);
			laptimeValueBestImageData.top = (int)(posY + GetPrivateProfileInt("Driver Timing.Laptime.Best", "image.top", 0, iniUIFilename) * ratioHeight);
			laptimeValueBestImageData.width = (int)(GetPrivateProfileInt("Driver Timing.Laptime.Best", "image.width", (int)spriteList[laptimeValueBestImageData.spriteIndex].width, iniUIFilename) * ratioWidth);
			laptimeValueBestImageData.height = (int)(GetPrivateProfileInt("Driver Timing.Laptime.Best", "image.height", (int)spriteList[laptimeValueBestImageData.spriteIndex].height, iniUIFilename) * ratioHeight);
			laptimeValueBestImageData.colorIndex = GetPrivateProfileInt("Driver Timing.Laptime.Best", "image.color.id", 1, iniUIFilename) -1;
		}
	}

	/////////////////////////////////////////////////////
	// Self Best
	/////////////////////////////////////////////////////
	selfBestValueAvailable = GetPrivateProfileInt("Driver Timing.SelfBest", "available", 0, iniUIFilename) != 0;
	if (selfBestValueAvailable) {
		selfBestValueTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Timing.SelfBest", "text.left", 0, iniUIFilename) * ratioWidth);
		selfBestValueTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Timing.SelfBest", "text.top", 0, iniUIFilename) * ratioWidth);
		selfBestValueTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Timing.SelfBest", "text.right", 100, iniUIFilename) * ratioWidth);
		selfBestValueTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Timing.SelfBest", "text.bottom", 100, iniUIFilename) * ratioWidth);

		selfBestValueTextData.fontIndex = GetPrivateProfileInt("Driver Timing.SelfBest", "text.font.id", 1, iniUIFilename) - 1;
		selfBestValueTextData.colorIndex = GetPrivateProfileInt("Driver Timing.SelfBest", "text.font.color.id", 1, iniUIFilename) - 1;
		selfBestValueTextData.alignment = GetPrivateProfileInt("Driver Timing.SelfBest", "text.alignment", 1, iniUIFilename);
	}

	/////////////////////////////////////////////////////
	// Leader Best
	/////////////////////////////////////////////////////
	leaderBestValueAvailable = GetPrivateProfileInt("Driver Timing.LeaderBest", "available", 0, iniUIFilename) != 0;
	if (leaderBestValueAvailable) {
		leaderBestValueTextData.rect.left = (int)(posX + GetPrivateProfileInt("Driver Timing.LeaderBest", "text.left", 0, iniUIFilename) * ratioWidth);
		leaderBestValueTextData.rect.top = (int)(posY + GetPrivateProfileInt("Driver Timing.LeaderBest", "text.top", 0, iniUIFilename) * ratioWidth);
		leaderBestValueTextData.rect.right = (int)(posX + GetPrivateProfileInt("Driver Timing.LeaderBest", "text.right", 100, iniUIFilename) * ratioWidth);
		leaderBestValueTextData.rect.bottom = (int)(posY + GetPrivateProfileInt("Driver Timing.LeaderBest", "text.bottom", 100, iniUIFilename) * ratioWidth);

		leaderBestValueTextData.fontIndex = GetPrivateProfileInt("Driver Timing.LeaderBest", "text.font.id", 1, iniUIFilename) - 1;
		leaderBestValueTextData.colorIndex = GetPrivateProfileInt("Driver Timing.LeaderBest", "text.font.color.id", 1, iniUIFilename) - 1;
		leaderBestValueTextData.alignment = GetPrivateProfileInt("Driver Timing.LeaderBest", "text.alignment", 1, iniUIFilename);
	}

	initialized = true;
}

	void DriverTiming::updateData(const ScoringInfoV01 &info, const VehicleScoringInfoV01 &vinfo, DriverInfo & di, TimingInfo & timingAllCategory, TimingInfo & timingInCategory) {
		if (!available) return;
		
		currentET = info.mCurrentET;

		if (memcmp(mLastDriverName, di.accountName, 32) != 0) {
			memcpy(&mLastDriverName, &di.accountName, 32);
			gapValue[0] = 0;
			pilotHaveChange = true;
			lastPilotChangeET = info.mCurrentET;
		}
		//if (di.timinigInfoInitialized) {
		//	if (di.mBestSector1 > 0 && di.timingInfoMyCat->bestSector1ID == di.mID) {
		//		haveBestS1InMyCat = true;
		//	} else { 
		//		haveBestS1InMyCat = false;
		//	}
		//}

		TimingInfo * currentTiming = NULL;
		bool b1;
		bool b2;
		bool b3;
		for (int i = 0; i < 2; i++) {
			if (i == 0) {
				currentTiming = &timingAllCategory;
			} else {
				currentTiming = &timingInCategory;
			}
				
			if (di.mBestSector1 > 0 && currentTiming->bestSector1ID == di.mID) {
				b1 = true;
			} else {
				b1 = false;
			}
			if (di.mBestSector2 > 0 && currentTiming->bestSector2ID == di.mID) {
				b2 = true;
			} else {
				b2 = false;
			}
			if (di.mBestLapTime > 0 && currentTiming->bestLaptimeID == di.mID) {
				b3 = true;
			} else {
				b3 = false;
			}

			if (i == 0) {
				haveBestS1InAllCat = b1;
				haveBestS2InAllCat = b2;
				haveBestS3InAllCat = b3;
			} else {
				haveBestS1InMyCat = b1;
				haveBestS2InMyCat = b2;
				haveBestS3InMyCat = b3;
			}
		}

		if (vinfo.mFinishStatus != 0) {
			//  1=finished, 2=dnf, 3=dq
			forceDisplay = false;
			isBetterLaptime = false;
			isWorstLaptime = false;
			isBestLaptime = false;

			isBetterGap = false;
			isWorstGap = false;

			sprintf(laptimeValue,"--:--.---");
			sprintf(s1Value,"--:--.---");
			sprintf(s2Value,"--:--.---");
			sprintf(s3Value,"--:--.---");
			gapValue[0] = 0;

			haveBetterS1 = false;
			haveWorstS1 = false;
			haveBetterS2 = false;
			haveWorstS2 = false;
			haveBetterS3 = false;
			haveWorstS3 = false;
		} else 	if (vinfo.mCurSector1 <= 0 && vinfo.mLastLapTime > 0 && vinfo.mTimeIntoLap < displayDurationUnpined && !pilotHaveChange) {
			// on vient de passer la ligne d'arriver, donc on freeze l'affichage pendant 7s
			forceDisplay = true;
			isBetterLaptime = false;
			isWorstLaptime = false;
			isBestLaptime = false;

			isBetterGap = false;
			isWorstGap = false;
			
			haveBetterS3 = false;
			haveWorstS3 = false;
			if (vinfo.mLastLapTime <= di.mBestLapTime || di.mBestLapTime <= 0) {
				haveBetterS3 = true;
			} else if (vinfo.mLastLapTime > di.mBestLapTime) {
				haveWorstS3 = true;
			}
			sprintf(s3Value, "%s", getTimeAsString(vinfo.mLastLapTime, false, false, true, true).c_str());
			double gap = vinfo.mLastLapTime - di.mBestLapTime;
			if (haveBetterS3) {
				gap = vinfo.mLastLapTime - di.oldBestLapTime;
			}
			if (gap > 0) {
				sprintf(gapValue, "+%s", getTimeAsString(gap, false, false, true, true).c_str());
				isWorstGap = true;
			} else {
				if (gap < 0) {
					isBetterGap = true;
				}
				sprintf(gapValue, "%s", getTimeAsString(gap, false, false, true, true).c_str());
			}

			if (gap < 0) {
				if (vinfo.mLastLapTime <= timingAllCategory.bestLaptime && timingAllCategory.bestLaptimeID == di.mID) {
					isBestLaptime = true;
				} else {
					isBetterLaptime = true;
				}
			} else if (gap > 0) {
				isWorstLaptime = true;
			}
			sprintf(laptimeValue, "%s", getTimeAsString(vinfo.mLastLapTime, false, false, true, true).c_str());
			
		} else {
			forceDisplay = false;

			if (vinfo.mTimeIntoLap >= displayDurationUnpined) {
				pilotHaveChange = false;
			}
			
			isBetterLaptime = false;
			isWorstLaptime = false;
			isBestLaptime = false;

			isBetterGap = false;
			isWorstGap = false;	

			// laptime
			if (vinfo.mLapStartET > 0 && !vinfo.mInPits) {
				sprintf(laptimeValue, "%s", getTimeAsString(di.currentLaptime, false, false, true, true).c_str());
			} else {
				sprintf(laptimeValue,"--:--.---");
			}
	

			// S1 Value
			haveBetterS1 = false;
			haveWorstS1 = false;
			if (vinfo.mCurSector1 > 0) {
				if (vinfo.mCurSector1 < di.mSector1OfBestLap || di.mSector1OfBestLap <= 0) {
					haveBetterS1 = true;
				} else if (vinfo.mCurSector1 > di.mSector1OfBestLap) {
					haveWorstS1 = true;
				}
				sprintf(s1Value, "%s", getTimeAsString(vinfo.mCurSector1, false, false, true, true).c_str());
				double gap = vinfo.mCurSector1 - di.mSector1OfBestLap;
				if( di.mSector1OfBestLap <= 0) gap = 0; 
				if (gap > 0) {
					isWorstGap = true;
					sprintf(gapValue, "+%s", getTimeAsString(gap, false, false, true, true).c_str());
				} else {
					if (gap < 0) {
						isBetterGap = true;
					}
					sprintf(gapValue, "%s", getTimeAsString(gap, false, false, true, true).c_str());
				}
			} else if (vinfo.mLapStartET > 0 && !vinfo.mInPits) {
				sprintf(s1Value, "%s", getTimeAsString(di.currentLaptime, false, false, true, true).c_str());
				gapValue[0] = 0;
			} else {
				sprintf(s1Value,"--:--.---");
				gapValue[0] = 0;
			}

			// S2 Value
			haveBetterS2 = false;
			haveWorstS2 = false;
			if (vinfo.mCurSector2 > 0) {
				if (vinfo.mCurSector2 < di.mSector2OfBestLap || di.mSector2OfBestLap <= 0) {
					haveBetterS2 = true;
				} else if (vinfo.mCurSector2 > di.mSector2OfBestLap) {
					haveWorstS2 = true;
				}
				sprintf(s2Value, "%s", getTimeAsString(vinfo.mCurSector2, false, false, true, true).c_str());
				double gap = vinfo.mCurSector2 - di.mSector2OfBestLap;
				if( di.mSector2OfBestLap <= 0) gap = 0; 
				if (gap > 0) {
					isWorstGap = true;
					sprintf(gapValue, "+%s", getTimeAsString(gap, false, false, true, true).c_str());
				} else {
					if (gap < 0) {
						isBetterGap = true;
					}
					sprintf(gapValue, "%s", getTimeAsString(gap, false, false, true, true).c_str());
				}
			} else if (vinfo.mCurSector1 > 0) {
				sprintf(s2Value, "%s", getTimeAsString(di.currentLaptime, false, false, true, true).c_str());
			} else {
				sprintf(s2Value,"--:--.---");
				gapValue[0] = 0;
			}

			// S3 Value
			haveBetterS3 = false;
			haveWorstS3 = false;
			// TODO comprendre pourquoi vinfo.mTimeIntoLap n'est pas le vrai temps (en s2 et s3 c'est de plus en plus different -> voir avec la version JAVA)
			if (vinfo.mCurSector2 > 0) {
				sprintf(s3Value, "%s", getTimeAsString(di.currentLaptime, false, false, true, true).c_str());
			} else {
				sprintf(s3Value,"--:--.---");
			}
		}

		// self best
		if (selfBestValueAvailable) {
			if (vinfo.mBestLapTime > 0) {
				sprintf(selfBestValue, "%s", getTimeAsString(di.mBestLapTime, false, false, true, true).c_str());
			} else {
				sprintf(selfBestValue,"--:--.---");
			}
		}
		// Leader best (cat)
		if (leaderBestValueAvailable) {
			if (timingInCategory.bestLaptime > 0) {
				sprintf(leaderBestValue, "%s", getTimeAsString(timingInCategory.bestLaptime, false, false, true, true).c_str());
			} else {
				sprintf(leaderBestValue,"--:--.---");
			}
		}
	}

	std::string DriverTiming::getTimeAsString(double seconds, bool forceAllFields, bool padHighest, bool showMillis, bool showFullMillis) {
		if ( showMillis )
            seconds = floor(0.5 + seconds * 1000 ) / 1000;
        else
            seconds = floor(0.5 + seconds );
        
		std:string str = "";

		if ( seconds < 0 )
        {
			str.append("-");
            seconds *= -1;
        }
        
        int hours = (int)( seconds / 3600 );
        
        if ( ( hours > 0 ) || forceAllFields )
        {
            if ( padHighest ) {
				if (hours < 10) {
					str.append("0");
				}
			}
			str.append(std::to_string(static_cast<long long>(hours)));
			str.append(":");
        }
        
        int minutes = ((int) ( seconds / 60 )) % 60 ;
        
        if ( ( hours > 0 ) || ( minutes > 0 ) || forceAllFields )
        {
            if ( ( hours > 0 ) || padHighest ) {
				if (minutes < 10) {
					str.append("0");
				}
			}
			str.append(std::to_string(static_cast<long long>(minutes)));
			str.append(":");
        }
        
        int restSeconds = showMillis ? ((int)floor(seconds)) % 60 : ((int)(floor(0.5 + seconds))) % 60 ;
        
        if ( ( hours > 0 ) || ( minutes > 0 ) || padHighest ) {
            if (restSeconds < 10) {
					str.append("0");
			}
		}
		str.append(std::to_string(static_cast<long long>(restSeconds)));
        
        if ( showMillis )
        {
            int millis = showFullMillis ? ( (int)floor( 0.5 + seconds * 1000 )) % 1000  : ((int) floor( 0.5 + seconds * 10 )) % 10 ;
			str.append(".");
            
            if ( showFullMillis ) {
				if (millis < 10) {
					str.append("00");
				} else if (millis < 100) {
					str.append("0");
				}
			}
			str.append(std::to_string(static_cast<long long>(millis)));
        }
		return str;
	}

	void DriverTiming::render(int profileIndex, const ScreenInfoV01 &info, const LPD3DXFONT *fontList, const D3DCOLOR *colorList, Sprite spriteList[]) { 
		if (!available) return;
		if (gReplayIsActive) return;
		if (profiles[profileIndex].hide) return;

		if (!isPinned && !forceDisplay) {
			// hide the Timing panel after 5s when not pinned
			return;
		}

		LPDIRECT3DDEVICE9 dev = static_cast<LPDIRECT3DDEVICE9>(info.mDevice);	
		if (bgImageData.spriteIndex > -1) {
			spriteList[bgImageData.spriteIndex].setPosition(bgImageData.left + profiles[profileIndex].widgetOffsetX, bgImageData.top + profiles[profileIndex].widgetOffsetY);
			spriteList[bgImageData.spriteIndex].setSize(bgImageData.width, bgImageData.height);
			spriteList[bgImageData.spriteIndex].render(dev, colorList[bgImageData.colorIndex], 100);
		}
		////////////////////////////////////////////
		// S1 
 		////////////////////////////////////////////
		// S1 Tag
		if (s1TagAllCatAvailable && haveBestS1InAllCat) {
			if (s1TagAllCatImageData.spriteIndex != -1) {
				spriteList[s1TagAllCatImageData.spriteIndex].setPosition(s1TagAllCatImageData.left + profiles[profileIndex].widgetOffsetX, s1TagAllCatImageData.top + profiles[profileIndex].widgetOffsetY);
				spriteList[s1TagAllCatImageData.spriteIndex].setSize(s1TagAllCatImageData.width, s1TagAllCatImageData.height);
				spriteList[s1TagAllCatImageData.spriteIndex].render(dev, colorList[s1TagAllCatImageData.colorIndex], 100);
			}
			tmpRect.left = s1TagAllCatTextData.rect.left + profiles[profileIndex].widgetOffsetX;
			tmpRect.top = s1TagAllCatTextData.rect.top + profiles[profileIndex].widgetOffsetY;
			tmpRect.right = s1TagAllCatTextData.rect.right + profiles[profileIndex].widgetOffsetX;
			tmpRect.bottom = s1TagAllCatTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
			fontList[s1TagAllCatTextData.fontIndex]->DrawTextA(NULL, "S1", -1, &tmpRect, s1TagAllCatTextData.alignment, colorList[s1TagAllCatTextData.colorIndex]);
		} else if (s1TagMyCatAvailable && haveBestS1InMyCat) {
			if (s1TagMyCatImageData.spriteIndex != -1) {
				spriteList[s1TagMyCatImageData.spriteIndex].setPosition(s1TagMyCatImageData.left + profiles[profileIndex].widgetOffsetX, s1TagMyCatImageData.top + profiles[profileIndex].widgetOffsetY);
				spriteList[s1TagMyCatImageData.spriteIndex].setSize(s1TagMyCatImageData.width, s1TagMyCatImageData.height);
				spriteList[s1TagMyCatImageData.spriteIndex].render(dev, colorList[s1TagMyCatImageData.colorIndex], 100);
			}
			tmpRect.left = s1TagMyCatTextData.rect.left + profiles[profileIndex].widgetOffsetX;
			tmpRect.top = s1TagMyCatTextData.rect.top + profiles[profileIndex].widgetOffsetY;
			tmpRect.right = s1TagMyCatTextData.rect.right + profiles[profileIndex].widgetOffsetX;
			tmpRect.bottom = s1TagMyCatTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
			fontList[s1TagMyCatTextData.fontIndex]->DrawTextA(NULL, "S1", -1, &tmpRect, s1TagMyCatTextData.alignment, colorList[s1TagMyCatTextData.colorIndex]);
		} else if (s1TagAvailable) {
			if (s1TagImageData.spriteIndex != -1) {
				spriteList[s1TagImageData.spriteIndex].setPosition(s1TagImageData.left + profiles[profileIndex].widgetOffsetX, s1TagImageData.top + profiles[profileIndex].widgetOffsetY);
				spriteList[s1TagImageData.spriteIndex].setSize(s1TagImageData.width, s1TagImageData.height);
				spriteList[s1TagImageData.spriteIndex].render(dev, colorList[s1TagImageData.colorIndex], 100);
			}
			tmpRect.left = s1TagTextData.rect.left + profiles[profileIndex].widgetOffsetX;
			tmpRect.top = s1TagTextData.rect.top + profiles[profileIndex].widgetOffsetY;
			tmpRect.right = s1TagTextData.rect.right + profiles[profileIndex].widgetOffsetX;
			tmpRect.bottom = s1TagTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
			fontList[s1TagTextData.fontIndex]->DrawTextA(NULL, "S1", -1, &tmpRect, s1TagTextData.alignment, colorList[s1TagTextData.colorIndex]);
		}
		// S1 Value
		if (s1ValueBetterAvailable && haveBetterS1) {
			if (s1ValueBetterImageData.spriteIndex != -1) {
				spriteList[s1ValueBetterImageData.spriteIndex].setPosition(s1ValueBetterImageData.left + profiles[profileIndex].widgetOffsetX, s1ValueBetterImageData.top + profiles[profileIndex].widgetOffsetY);
				spriteList[s1ValueBetterImageData.spriteIndex].setSize(s1ValueBetterImageData.width, s1ValueBetterImageData.height);
				spriteList[s1ValueBetterImageData.spriteIndex].render(dev, colorList[s1ValueBetterImageData.colorIndex], 100);
			}
			tmpRect.left = s1ValueBetterTextData.rect.left + profiles[profileIndex].widgetOffsetX;
			tmpRect.top = s1ValueBetterTextData.rect.top + profiles[profileIndex].widgetOffsetY;
			tmpRect.right = s1ValueBetterTextData.rect.right + profiles[profileIndex].widgetOffsetX;
			tmpRect.bottom = s1ValueBetterTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
			fontList[s1ValueBetterTextData.fontIndex]->DrawTextA(NULL, s1Value, -1, &tmpRect, s1ValueBetterTextData.alignment, colorList[s1ValueBetterTextData.colorIndex]);
		} else if (s1ValueWorstAvailable && haveWorstS1) {
			if (s1ValueWorstImageData.spriteIndex != -1) {
				spriteList[s1ValueWorstImageData.spriteIndex].setPosition(s1ValueWorstImageData.left + profiles[profileIndex].widgetOffsetX, s1ValueWorstImageData.top + profiles[profileIndex].widgetOffsetY);
				spriteList[s1ValueWorstImageData.spriteIndex].setSize(s1ValueWorstImageData.width, s1ValueWorstImageData.height);
				spriteList[s1ValueWorstImageData.spriteIndex].render(dev, colorList[s1ValueWorstImageData.colorIndex], 100);
			}
			tmpRect.left = s1ValueWorstTextData.rect.left + profiles[profileIndex].widgetOffsetX;
			tmpRect.top = s1ValueWorstTextData.rect.top + profiles[profileIndex].widgetOffsetY;
			tmpRect.right = s1ValueWorstTextData.rect.right + profiles[profileIndex].widgetOffsetX;
			tmpRect.bottom = s1ValueWorstTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
			fontList[s1ValueWorstTextData.fontIndex]->DrawTextA(NULL, s1Value, -1, &tmpRect, s1ValueWorstTextData.alignment, colorList[s1ValueWorstTextData.colorIndex]);
		} else if (s1ValueAvailable) {
			if (s1ValueImageData.spriteIndex != -1) {
				spriteList[s1ValueImageData.spriteIndex].setPosition(s1ValueImageData.left + profiles[profileIndex].widgetOffsetX, s1ValueImageData.top + profiles[profileIndex].widgetOffsetY);
				spriteList[s1ValueImageData.spriteIndex].setSize(s1ValueImageData.width, s1ValueImageData.height);
				spriteList[s1ValueImageData.spriteIndex].render(dev, colorList[s1ValueImageData.colorIndex], 100);
			}
			tmpRect.left = s1ValueTextData.rect.left + profiles[profileIndex].widgetOffsetX;
			tmpRect.top = s1ValueTextData.rect.top + profiles[profileIndex].widgetOffsetY;
			tmpRect.right = s1ValueTextData.rect.right + profiles[profileIndex].widgetOffsetX;
			tmpRect.bottom = s1ValueTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
			fontList[s1ValueTextData.fontIndex]->DrawTextA(NULL, s1Value, -1, &tmpRect, s1ValueTextData.alignment, colorList[s1ValueTextData.colorIndex]);
		}


		////////////////////////////////////////////
		// S2 (S2 + S1) 
 		////////////////////////////////////////////
		// S2 Tag
		if (s2TagAllCatAvailable && haveBestS2InAllCat) {
			if (s2TagAllCatImageData.spriteIndex != -1) {
				spriteList[s2TagAllCatImageData.spriteIndex].setPosition(s2TagAllCatImageData.left + profiles[profileIndex].widgetOffsetX, s2TagAllCatImageData.top + profiles[profileIndex].widgetOffsetY);
				spriteList[s2TagAllCatImageData.spriteIndex].setSize(s2TagAllCatImageData.width, s2TagAllCatImageData.height);
				spriteList[s2TagAllCatImageData.spriteIndex].render(dev, colorList[s2TagAllCatImageData.colorIndex], 100);
			}
			tmpRect.left = s2TagAllCatTextData.rect.left + profiles[profileIndex].widgetOffsetX;
			tmpRect.top = s2TagAllCatTextData.rect.top + profiles[profileIndex].widgetOffsetY;
			tmpRect.right = s2TagAllCatTextData.rect.right + profiles[profileIndex].widgetOffsetX;
			tmpRect.bottom = s2TagAllCatTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
			fontList[s2TagAllCatTextData.fontIndex]->DrawTextA(NULL, "S2", -1, &tmpRect, s2TagAllCatTextData.alignment, colorList[s2TagAllCatTextData.colorIndex]);
		} else if (s2TagMyCatAvailable && haveBestS2InMyCat) {
			if (s2TagMyCatImageData.spriteIndex != -1) {
				spriteList[s2TagMyCatImageData.spriteIndex].setPosition(s2TagMyCatImageData.left + profiles[profileIndex].widgetOffsetX, s2TagMyCatImageData.top + profiles[profileIndex].widgetOffsetY);
				spriteList[s2TagMyCatImageData.spriteIndex].setSize(s2TagMyCatImageData.width, s2TagMyCatImageData.height);
				spriteList[s2TagMyCatImageData.spriteIndex].render(dev, colorList[s2TagMyCatImageData.colorIndex], 100);
			}
			tmpRect.left = s2TagMyCatTextData.rect.left + profiles[profileIndex].widgetOffsetX;
			tmpRect.top = s2TagMyCatTextData.rect.top + profiles[profileIndex].widgetOffsetY;
			tmpRect.right = s2TagMyCatTextData.rect.right + profiles[profileIndex].widgetOffsetX;
			tmpRect.bottom = s2TagMyCatTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
			fontList[s2TagMyCatTextData.fontIndex]->DrawTextA(NULL, "S2", -1, &tmpRect, s2TagMyCatTextData.alignment, colorList[s2TagMyCatTextData.colorIndex]);
		} else if (s2TagAvailable) {
			if (s2TagImageData.spriteIndex != -1) {
				spriteList[s2TagImageData.spriteIndex].setPosition(s2TagImageData.left + profiles[profileIndex].widgetOffsetX, s2TagImageData.top + profiles[profileIndex].widgetOffsetY);
				spriteList[s2TagImageData.spriteIndex].setSize(s2TagImageData.width, s2TagImageData.height);
				spriteList[s2TagImageData.spriteIndex].render(dev, colorList[s2TagImageData.colorIndex], 100);
			}
			tmpRect.left = s2TagTextData.rect.left + profiles[profileIndex].widgetOffsetX;
			tmpRect.top = s2TagTextData.rect.top + profiles[profileIndex].widgetOffsetY;
			tmpRect.right = s2TagTextData.rect.right + profiles[profileIndex].widgetOffsetX;
			tmpRect.bottom = s2TagTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
			fontList[s2TagTextData.fontIndex]->DrawTextA(NULL, "S2", -1, &tmpRect, s2TagTextData.alignment, colorList[s2TagTextData.colorIndex]);
		}
		// S2 Value
		if (s2ValueBetterAvailable && haveBetterS2) {
			if (s2ValueBetterImageData.spriteIndex != -1) {
				spriteList[s2ValueBetterImageData.spriteIndex].setPosition(s2ValueBetterImageData.left + profiles[profileIndex].widgetOffsetX, s2ValueBetterImageData.top + profiles[profileIndex].widgetOffsetY);
				spriteList[s2ValueBetterImageData.spriteIndex].setSize(s2ValueBetterImageData.width, s2ValueBetterImageData.height);
				spriteList[s2ValueBetterImageData.spriteIndex].render(dev, colorList[s2ValueBetterImageData.colorIndex], 100);
			}
			tmpRect.left = s2ValueBetterTextData.rect.left + profiles[profileIndex].widgetOffsetX;
			tmpRect.top = s2ValueBetterTextData.rect.top + profiles[profileIndex].widgetOffsetY;
			tmpRect.right = s2ValueBetterTextData.rect.right + profiles[profileIndex].widgetOffsetX;
			tmpRect.bottom = s2ValueBetterTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
			fontList[s2ValueBetterTextData.fontIndex]->DrawTextA(NULL, s2Value, -1, &tmpRect, s2ValueBetterTextData.alignment, colorList[s2ValueBetterTextData.colorIndex]);
		} else if (s2ValueWorstAvailable && haveWorstS2) {
			if (s2ValueWorstImageData.spriteIndex != -1) {
				spriteList[s2ValueWorstImageData.spriteIndex].setPosition(s2ValueWorstImageData.left + profiles[profileIndex].widgetOffsetX, s2ValueWorstImageData.top + profiles[profileIndex].widgetOffsetY);
				spriteList[s2ValueWorstImageData.spriteIndex].setSize(s2ValueWorstImageData.width, s2ValueWorstImageData.height);
				spriteList[s2ValueWorstImageData.spriteIndex].render(dev, colorList[s2ValueWorstImageData.colorIndex], 100);
			}
			tmpRect.left = s2ValueWorstTextData.rect.left + profiles[profileIndex].widgetOffsetX;
			tmpRect.top = s2ValueWorstTextData.rect.top + profiles[profileIndex].widgetOffsetY;
			tmpRect.right = s2ValueWorstTextData.rect.right + profiles[profileIndex].widgetOffsetX;
			tmpRect.bottom = s2ValueWorstTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
			fontList[s2ValueWorstTextData.fontIndex]->DrawTextA(NULL, s2Value, -1, &tmpRect, s2ValueWorstTextData.alignment, colorList[s2ValueWorstTextData.colorIndex]);
		} else if (s2ValueAvailable) {
			if (s2ValueImageData.spriteIndex != -1) {
				spriteList[s2ValueImageData.spriteIndex].setPosition(s2ValueImageData.left + profiles[profileIndex].widgetOffsetX, s2ValueImageData.top + profiles[profileIndex].widgetOffsetY);
				spriteList[s2ValueImageData.spriteIndex].setSize(s2ValueImageData.width, s2ValueImageData.height);
				spriteList[s2ValueImageData.spriteIndex].render(dev, colorList[s2ValueImageData.colorIndex], 100);
			}
			tmpRect.left = s2ValueTextData.rect.left + profiles[profileIndex].widgetOffsetX;
			tmpRect.top = s2ValueTextData.rect.top + profiles[profileIndex].widgetOffsetY;
			tmpRect.right = s2ValueTextData.rect.right + profiles[profileIndex].widgetOffsetX;
			tmpRect.bottom = s2ValueTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
			fontList[s2ValueTextData.fontIndex]->DrawTextA(NULL, s2Value, -1, &tmpRect, s2ValueTextData.alignment, colorList[s2ValueTextData.colorIndex]);
		}

		////////////////////////////////////////////
		// S3 (Laptime) 
 		////////////////////////////////////////////
		// S3 Tag
		if (s3TagAllCatAvailable && haveBestS3InAllCat) {
			if (s3TagAllCatImageData.spriteIndex != -1) {
				spriteList[s3TagAllCatImageData.spriteIndex].setPosition(s3TagAllCatImageData.left + profiles[profileIndex].widgetOffsetX, s3TagAllCatImageData.top + profiles[profileIndex].widgetOffsetY);
				spriteList[s3TagAllCatImageData.spriteIndex].setSize(s3TagAllCatImageData.width, s3TagAllCatImageData.height);
				spriteList[s3TagAllCatImageData.spriteIndex].render(dev, colorList[s3TagAllCatImageData.colorIndex], 100);
			}
			tmpRect.left = s3TagAllCatTextData.rect.left + profiles[profileIndex].widgetOffsetX;
			tmpRect.top = s3TagAllCatTextData.rect.top + profiles[profileIndex].widgetOffsetY;
			tmpRect.right = s3TagAllCatTextData.rect.right + profiles[profileIndex].widgetOffsetX;
			tmpRect.bottom = s3TagAllCatTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
			fontList[s3TagAllCatTextData.fontIndex]->DrawTextA(NULL, "S3", -1, &tmpRect, s3TagAllCatTextData.alignment, colorList[s3TagAllCatTextData.colorIndex]);
		} else if (s3TagMyCatAvailable && haveBestS3InMyCat) {
			if (s3TagMyCatImageData.spriteIndex != -1) {
				spriteList[s3TagMyCatImageData.spriteIndex].setPosition(s3TagMyCatImageData.left + profiles[profileIndex].widgetOffsetX, s3TagMyCatImageData.top + profiles[profileIndex].widgetOffsetY);
				spriteList[s3TagMyCatImageData.spriteIndex].setSize(s3TagMyCatImageData.width, s3TagMyCatImageData.height);
				spriteList[s3TagMyCatImageData.spriteIndex].render(dev, colorList[s3TagMyCatImageData.colorIndex], 100);
			}
			tmpRect.left = s3TagMyCatTextData.rect.left + profiles[profileIndex].widgetOffsetX;
			tmpRect.top = s3TagMyCatTextData.rect.top + profiles[profileIndex].widgetOffsetY;
			tmpRect.right = s3TagMyCatTextData.rect.right + profiles[profileIndex].widgetOffsetX;
			tmpRect.bottom = s3TagMyCatTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
			fontList[s3TagMyCatTextData.fontIndex]->DrawTextA(NULL, "S3", -1, &tmpRect, s3TagMyCatTextData.alignment, colorList[s3TagMyCatTextData.colorIndex]);
		} else if (s3TagAvailable) {
			if (s3TagImageData.spriteIndex != -1) {
				spriteList[s3TagImageData.spriteIndex].setPosition(s3TagImageData.left + profiles[profileIndex].widgetOffsetX, s3TagImageData.top + profiles[profileIndex].widgetOffsetY);
				spriteList[s3TagImageData.spriteIndex].setSize(s3TagImageData.width, s3TagImageData.height);
				spriteList[s3TagImageData.spriteIndex].render(dev, colorList[s3TagImageData.colorIndex], 100);
			}
			tmpRect.left = s3TagTextData.rect.left + profiles[profileIndex].widgetOffsetX;
			tmpRect.top = s3TagTextData.rect.top + profiles[profileIndex].widgetOffsetY;
			tmpRect.right = s3TagTextData.rect.right + profiles[profileIndex].widgetOffsetX;
			tmpRect.bottom = s3TagTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
			fontList[s3TagTextData.fontIndex]->DrawTextA(NULL, "S3", -1, &tmpRect, s3TagTextData.alignment, colorList[s3TagTextData.colorIndex]);
		}
		// S3 Value
		if (s3ValueBetterAvailable && haveBetterS3) {
			if (s3ValueBetterImageData.spriteIndex != -1) {
				spriteList[s3ValueBetterImageData.spriteIndex].setPosition(s3ValueBetterImageData.left + profiles[profileIndex].widgetOffsetX, s3ValueBetterImageData.top + profiles[profileIndex].widgetOffsetY);
				spriteList[s3ValueBetterImageData.spriteIndex].setSize(s3ValueBetterImageData.width, s3ValueBetterImageData.height);
				spriteList[s3ValueBetterImageData.spriteIndex].render(dev, colorList[s3ValueBetterImageData.colorIndex], 100);
			}
			tmpRect.left = s3ValueBetterTextData.rect.left + profiles[profileIndex].widgetOffsetX;
			tmpRect.top = s3ValueBetterTextData.rect.top + profiles[profileIndex].widgetOffsetY;
			tmpRect.right = s3ValueBetterTextData.rect.right + profiles[profileIndex].widgetOffsetX;
			tmpRect.bottom = s3ValueBetterTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
			fontList[s3ValueBetterTextData.fontIndex]->DrawTextA(NULL, s3Value, -1, &tmpRect, s3ValueBetterTextData.alignment, colorList[s3ValueBetterTextData.colorIndex]);
		} else if (s3ValueWorstAvailable && haveWorstS3) {
			if (s3ValueWorstImageData.spriteIndex != -1) {
				spriteList[s3ValueWorstImageData.spriteIndex].setPosition(s3ValueWorstImageData.left + profiles[profileIndex].widgetOffsetX, s3ValueWorstImageData.top + profiles[profileIndex].widgetOffsetY);
				spriteList[s3ValueWorstImageData.spriteIndex].setSize(s3ValueWorstImageData.width, s3ValueWorstImageData.height);
				spriteList[s3ValueWorstImageData.spriteIndex].render(dev, colorList[s3ValueWorstImageData.colorIndex], 100);
			}
			tmpRect.left = s3ValueWorstTextData.rect.left + profiles[profileIndex].widgetOffsetX;
			tmpRect.top = s3ValueWorstTextData.rect.top + profiles[profileIndex].widgetOffsetY;
			tmpRect.right = s3ValueWorstTextData.rect.right + profiles[profileIndex].widgetOffsetX;
			tmpRect.bottom = s3ValueWorstTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
			fontList[s3ValueWorstTextData.fontIndex]->DrawTextA(NULL, s3Value, -1, &tmpRect, s3ValueWorstTextData.alignment, colorList[s3ValueWorstTextData.colorIndex]);
		} else if (s3ValueAvailable) {
			if (s3ValueImageData.spriteIndex != -1) {
				spriteList[s3ValueImageData.spriteIndex].setPosition(s3ValueImageData.left + profiles[profileIndex].widgetOffsetX, s3ValueImageData.top + profiles[profileIndex].widgetOffsetY);
				spriteList[s3ValueImageData.spriteIndex].setSize(s3ValueImageData.width, s3ValueImageData.height);
				spriteList[s3ValueImageData.spriteIndex].render(dev, colorList[s3ValueImageData.colorIndex], 100);
			}
			tmpRect.left = s3ValueTextData.rect.left + profiles[profileIndex].widgetOffsetX;
			tmpRect.top = s3ValueTextData.rect.top + profiles[profileIndex].widgetOffsetY;
			tmpRect.right = s3ValueTextData.rect.right + profiles[profileIndex].widgetOffsetX;
			tmpRect.bottom = s3ValueTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
			fontList[s3ValueTextData.fontIndex]->DrawTextA(NULL, s3Value, -1, &tmpRect, s3ValueTextData.alignment, colorList[s3ValueTextData.colorIndex]);
		}

		//////////////////////////////////
		// Gap
		//////////////////////////////////
		if (gapValueBetterAvailable && isBetterGap) {
			if (gapValueBetterImageData.spriteIndex != -1) {
				spriteList[gapValueBetterImageData.spriteIndex].setPosition(gapValueBetterImageData.left + profiles[profileIndex].widgetOffsetX, gapValueBetterImageData.top + profiles[profileIndex].widgetOffsetY);
				spriteList[gapValueBetterImageData.spriteIndex].setSize(gapValueBetterImageData.width, gapValueBetterImageData.height);
				spriteList[gapValueBetterImageData.spriteIndex].render(dev, colorList[gapValueBetterImageData.colorIndex], 100);
			}
			tmpRect.left = gapValueBetterTextData.rect.left + profiles[profileIndex].widgetOffsetX;
			tmpRect.top = gapValueBetterTextData.rect.top + profiles[profileIndex].widgetOffsetY;
			tmpRect.right = gapValueBetterTextData.rect.right + profiles[profileIndex].widgetOffsetX;
			tmpRect.bottom = gapValueBetterTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
			fontList[gapValueBetterTextData.fontIndex]->DrawTextA(NULL, gapValue, -1, &tmpRect, gapValueBetterTextData.alignment, colorList[gapValueBetterTextData.colorIndex]);
		} else if (gapValueWorstAvailable && isWorstGap) {
			if (gapValueWorstImageData.spriteIndex != -1) {
				spriteList[gapValueWorstImageData.spriteIndex].setPosition(gapValueWorstImageData.left + profiles[profileIndex].widgetOffsetX, gapValueWorstImageData.top + profiles[profileIndex].widgetOffsetY);
				spriteList[gapValueWorstImageData.spriteIndex].setSize(gapValueWorstImageData.width, gapValueWorstImageData.height);
				spriteList[gapValueWorstImageData.spriteIndex].render(dev, colorList[gapValueWorstImageData.colorIndex], 100);
			}
			tmpRect.left = gapValueWorstTextData.rect.left + profiles[profileIndex].widgetOffsetX;
			tmpRect.top = gapValueWorstTextData.rect.top + profiles[profileIndex].widgetOffsetY;
			tmpRect.right = gapValueWorstTextData.rect.right + profiles[profileIndex].widgetOffsetX;
			tmpRect.bottom = gapValueWorstTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
			fontList[gapValueWorstTextData.fontIndex]->DrawTextA(NULL, gapValue, -1, &tmpRect, gapValueWorstTextData.alignment, colorList[gapValueWorstTextData.colorIndex]);
		} else if (gapValueAvailable) {
			if (gapValueImageData.spriteIndex != -1) {
				spriteList[gapValueImageData.spriteIndex].setPosition(gapValueImageData.left + profiles[profileIndex].widgetOffsetX, gapValueImageData.top + profiles[profileIndex].widgetOffsetY);
				spriteList[gapValueImageData.spriteIndex].setSize(gapValueImageData.width, gapValueImageData.height);
				spriteList[gapValueImageData.spriteIndex].render(dev, colorList[gapValueImageData.colorIndex], 100);
			}
			tmpRect.left = gapValueTextData.rect.left + profiles[profileIndex].widgetOffsetX;
			tmpRect.top = gapValueTextData.rect.top + profiles[profileIndex].widgetOffsetY;
			tmpRect.right = gapValueTextData.rect.right + profiles[profileIndex].widgetOffsetX;
			tmpRect.bottom = gapValueTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
			fontList[gapValueTextData.fontIndex]->DrawTextA(NULL, gapValue, -1, &tmpRect, gapValueTextData.alignment, colorList[gapValueTextData.colorIndex]);
		}

		//////////////////////////////////
		// Laptime
		//////////////////////////////////
		if (laptimeValueBestAvailable && isBestLaptime) {
			if (laptimeValueBestImageData.spriteIndex != -1) {
				spriteList[laptimeValueBestImageData.spriteIndex].setPosition(laptimeValueBestImageData.left + profiles[profileIndex].widgetOffsetX, laptimeValueBestImageData.top + profiles[profileIndex].widgetOffsetY);
				spriteList[laptimeValueBestImageData.spriteIndex].setSize(laptimeValueBestImageData.width, laptimeValueBestImageData.height);
				spriteList[laptimeValueBestImageData.spriteIndex].render(dev, colorList[laptimeValueBestImageData.colorIndex], 100);
			}
			tmpRect.left = laptimeValueBestTextData.rect.left + profiles[profileIndex].widgetOffsetX;
			tmpRect.top = laptimeValueBestTextData.rect.top + profiles[profileIndex].widgetOffsetY;
			tmpRect.right = laptimeValueBestTextData.rect.right + profiles[profileIndex].widgetOffsetX;
			tmpRect.bottom = laptimeValueBestTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
			fontList[laptimeValueBestTextData.fontIndex]->DrawTextA(NULL, laptimeValue, -1, &tmpRect, laptimeValueBestTextData.alignment, colorList[laptimeValueBestTextData.colorIndex]);
		} else if (laptimeValueBetterAvailable && isBetterLaptime) {
			if (laptimeValueBetterImageData.spriteIndex != -1) {
				spriteList[laptimeValueBetterImageData.spriteIndex].setPosition(laptimeValueBetterImageData.left + profiles[profileIndex].widgetOffsetX, laptimeValueBetterImageData.top + profiles[profileIndex].widgetOffsetY);
				spriteList[laptimeValueBetterImageData.spriteIndex].setSize(laptimeValueBetterImageData.width, laptimeValueBetterImageData.height);
				spriteList[laptimeValueBetterImageData.spriteIndex].render(dev, colorList[laptimeValueBetterImageData.colorIndex], 100);
			}
			tmpRect.left = laptimeValueBetterTextData.rect.left + profiles[profileIndex].widgetOffsetX;
			tmpRect.top = laptimeValueBetterTextData.rect.top + profiles[profileIndex].widgetOffsetY;
			tmpRect.right = laptimeValueBetterTextData.rect.right + profiles[profileIndex].widgetOffsetX;
			tmpRect.bottom = laptimeValueBetterTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
			fontList[laptimeValueBetterTextData.fontIndex]->DrawTextA(NULL, laptimeValue, -1, &tmpRect, laptimeValueBetterTextData.alignment, colorList[laptimeValueBetterTextData.colorIndex]);
		} else if (laptimeValueWorstAvailable && isWorstLaptime) {
			if (laptimeValueWorstImageData.spriteIndex != -1) {
				spriteList[laptimeValueWorstImageData.spriteIndex].setPosition(laptimeValueWorstImageData.left + profiles[profileIndex].widgetOffsetX, laptimeValueWorstImageData.top + profiles[profileIndex].widgetOffsetY);
				spriteList[laptimeValueWorstImageData.spriteIndex].setSize(laptimeValueWorstImageData.width, laptimeValueWorstImageData.height);
				spriteList[laptimeValueWorstImageData.spriteIndex].render(dev, colorList[laptimeValueWorstImageData.colorIndex], 100);
			}
			tmpRect.left = laptimeValueWorstTextData.rect.left + profiles[profileIndex].widgetOffsetX;
			tmpRect.top = laptimeValueWorstTextData.rect.top + profiles[profileIndex].widgetOffsetY;
			tmpRect.right = laptimeValueWorstTextData.rect.right + profiles[profileIndex].widgetOffsetX;
			tmpRect.bottom = laptimeValueWorstTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
			fontList[laptimeValueWorstTextData.fontIndex]->DrawTextA(NULL, laptimeValue, -1, &tmpRect, laptimeValueWorstTextData.alignment, colorList[laptimeValueWorstTextData.colorIndex]);
		} else if (laptimeValueAvailable) {
			if (laptimeValueImageData.spriteIndex != -1) {
				spriteList[laptimeValueImageData.spriteIndex].setPosition(laptimeValueImageData.left + profiles[profileIndex].widgetOffsetX, laptimeValueImageData.top + profiles[profileIndex].widgetOffsetY);
				spriteList[laptimeValueImageData.spriteIndex].setSize(laptimeValueImageData.width, laptimeValueImageData.height);
				spriteList[laptimeValueImageData.spriteIndex].render(dev, colorList[laptimeValueImageData.colorIndex], 100);
			}
			tmpRect.left = laptimeValueTextData.rect.left + profiles[profileIndex].widgetOffsetX;
			tmpRect.top = laptimeValueTextData.rect.top + profiles[profileIndex].widgetOffsetY;
			tmpRect.right = laptimeValueTextData.rect.right + profiles[profileIndex].widgetOffsetX;
			tmpRect.bottom = laptimeValueTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
			fontList[laptimeValueTextData.fontIndex]->DrawTextA(NULL, laptimeValue, -1, &tmpRect, laptimeValueTextData.alignment, colorList[laptimeValueTextData.colorIndex]);
		}

		//////////////////////////////////
		// Self Best
		//////////////////////////////////
		if (selfBestValueAvailable) {
			tmpRect.left = selfBestValueTextData.rect.left + profiles[profileIndex].widgetOffsetX;
			tmpRect.top = selfBestValueTextData.rect.top + profiles[profileIndex].widgetOffsetY;
			tmpRect.right = selfBestValueTextData.rect.right + profiles[profileIndex].widgetOffsetX;
			tmpRect.bottom = selfBestValueTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
			fontList[selfBestValueTextData.fontIndex]->DrawTextA(NULL, selfBestValue, -1, &tmpRect, selfBestValueTextData.alignment, colorList[selfBestValueTextData.colorIndex]);
		}
		//////////////////////////////////
		// Leader Best
		//////////////////////////////////
		if (leaderBestValueAvailable) {
			tmpRect.left = leaderBestValueTextData.rect.left + profiles[profileIndex].widgetOffsetX;
			tmpRect.top = leaderBestValueTextData.rect.top + profiles[profileIndex].widgetOffsetY;
			tmpRect.right = leaderBestValueTextData.rect.right + profiles[profileIndex].widgetOffsetX;
			tmpRect.bottom = leaderBestValueTextData.rect.bottom + profiles[profileIndex].widgetOffsetY;
			fontList[leaderBestValueTextData.fontIndex]->DrawTextA(NULL, leaderBestValue, -1, &tmpRect, leaderBestValueTextData.alignment, colorList[leaderBestValueTextData.colorIndex]);
		}
	}

DriverTiming::~DriverTiming(void)
{
}
